Commit d50a2580 d50a25809b8017b2017e0dc4e112fe3e423d8008 by Alain Magloire

This is after an exchange with Dave Inglis and Sam Roberts.

	Basically they recommand to drop the XX_release() functions
	and only to keep XX_create (), XX_destroy ().  We have simple
	reference count strategy for memory management.

	* mailbox2/* : Way too much to enumerate.
	* mailbox2/refcount.c: New file
	* mailbox2/include/mailutils/refcount.h: New file
	* mailbox2/include/mailutils/sys/refcount.h: New file
	* mailbox2/fdstream.c: stream_fd_create ().
1 parent 48f314aa
Showing 84 changed files with 1869 additions and 1485 deletions
......@@ -15,8 +15,10 @@ libmailbox_la_SOURCES = \
attribute.c \
authority.c \
bstream.c \
dattribute.c \
dotlock.c \
envelope.c \
fdstream.c \
folder.c \
fstream.c \
header.c \
......@@ -33,6 +35,7 @@ libmailbox_la_SOURCES = \
observer.c \
parse822.c \
pticket.c \
refcount.c \
stream.c \
tcpstream.c \
ticket.c
......
......@@ -54,19 +54,21 @@ address_create (address_t *a, const char *s)
(*a)->addr = strdup (s);
if (!(*a)->addr)
{
address_destroy (*a);
address_destroy (a);
return ENOMEM;
}
}
return status;
}
int
address_destroy (address_t address)
void
address_destroy (address_t *paddress)
{
if (address)
if (paddress && *paddress)
{
address_t current;
address_t address = *paddress;
for (; address; address = current)
{
if (address->addr)
......@@ -86,8 +88,8 @@ address_destroy (address_t address)
current = address->next;
free (address);
}
*paddress = NULL;
}
return 0;
}
int
......
......@@ -20,45 +20,33 @@
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <mailutils/error.h>
#include <mailutils/sys/attribute.h>
int
(attribute_add_ref) (attribute_t attribute)
attribute_ref (attribute_t attribute)
{
if (attribute == NULL || attribute->vtable == NULL
|| attribute->vtable->add_ref == NULL)
|| attribute->vtable->ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return attribute->vtable->add_ref (attribute);
return attribute->vtable->ref (attribute);
}
int
(attribute_release) (attribute_t attribute)
void
attribute_destroy (attribute_t *pattribute)
{
if (attribute == NULL || attribute->vtable == NULL
|| attribute->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return attribute->vtable->release (attribute);
}
int
(attribute_destroy) (attribute_t attribute)
{
if (attribute == NULL || attribute->vtable == NULL
|| attribute->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return attribute->vtable->destroy (attribute);
if (pattribute && *pattribute)
{
attribute_t attribute = *pattribute;
if (attribute->vtable && attribute->vtable->destroy)
attribute->vtable->destroy (pattribute);
*pattribute = NULL;
}
}
int
(attribute_get_flags) (attribute_t attribute, int *pflags)
attribute_get_flags (attribute_t attribute, int *pflags)
{
if (attribute == NULL || attribute->vtable == NULL
|| attribute->vtable->get_flags == NULL)
......@@ -67,7 +55,7 @@ int
}
int
(attribute_set_flags) (attribute_t attribute, int flags)
attribute_set_flags (attribute_t attribute, int flags)
{
if (attribute == NULL || attribute->vtable == NULL
|| attribute->vtable->set_flags == NULL)
......@@ -76,7 +64,7 @@ int
}
int
(attribute_unset_flags) (attribute_t attribute, int flags)
attribute_unset_flags (attribute_t attribute, int flags)
{
if (attribute == NULL || attribute->vtable == NULL
|| attribute->vtable->unset_flags == NULL)
......@@ -85,7 +73,7 @@ int
}
int
(attribute_clear_flags) (attribute_t attribute)
attribute_clear_flags (attribute_t attribute)
{
if (attribute == NULL || attribute->vtable == NULL
|| attribute->vtable->clear_flags == NULL)
......@@ -330,114 +318,3 @@ attribute_copy (attribute_t dest, attribute_t src)
attribute_set_flags (dest, sflags);
return 0;
}
static int
_da_add_ref (attribute_t attribute)
{
struct _da *da = (struct _da *)attribute;
int status;
monitor_lock (da->lock);
status = ++da->ref;
monitor_unlock (da->lock);
return status;
}
static int
_da_destroy (attribute_t attribute)
{
struct _da *da = (struct _da *)attribute;
monitor_destroy (da->lock);
free (da);
return 0;
}
static int
_da_release (attribute_t attribute)
{
struct _da *da = (struct _da *)attribute;
int status;
monitor_lock (da->lock);
status = --da->ref;
if (status <= 0)
{
monitor_unlock (da->lock);
_da_destroy (attribute);
return 0;
}
monitor_unlock (da->lock);
return status;
}
static int
_da_get_flags (attribute_t attribute, int *pflags)
{
struct _da *da = (struct _da *)attribute;
monitor_lock (da->lock);
if (pflags)
*pflags = da->flags;
monitor_unlock (da->lock);
return 0;
}
static int
_da_set_flags (attribute_t attribute, int flags)
{
struct _da *da = (struct _da *)attribute;
monitor_lock (da->lock);
da->flags |= (flags | MU_ATTRIBUTE_MODIFIED);
monitor_unlock (da->lock);
return 0;
}
static int
_da_unset_flags (attribute_t attribute, int flags)
{
struct _da *da = (struct _da *)attribute;
monitor_lock (da->lock);
da->flags &= ~flags;
/* If Modified was being unset do not reset it. */
if (!(flags & MU_ATTRIBUTE_MODIFIED))
da->flags |= MU_ATTRIBUTE_MODIFIED;
monitor_unlock (da->lock);
return 0;
}
static int
_da_clear_flags (attribute_t attribute)
{
struct _da *da = (struct _da *)attribute;
monitor_lock (da->lock);
da->flags = 0;
monitor_unlock (da->lock);
return 0;
}
static struct _attribute_vtable _da_vtable =
{
_da_add_ref,
_da_release,
_da_destroy,
_da_get_flags,
_da_set_flags,
_da_unset_flags,
_da_clear_flags
};
int
attribute_create (attribute_t *pattribute)
{
struct _da *da;
if (pattribute == NULL)
return MU_ERROR_INVALID_PARAMETER;
da = calloc (1, sizeof *da);
if (da == NULL)
return MU_ERROR_NO_MEMORY;
da->base.vtable = &_da_vtable;
da->ref = 1;
da->flags = 0;
monitor_create (&(da->lock));
*pattribute = &da->base;
return 0;
}
......
......@@ -23,30 +23,24 @@
#include <mailutils/sys/authority.h>
int
authority_add_ref (authority_t authority)
authority_ref (authority_t authority)
{
if (authority == NULL || authority->vtable == NULL
|| authority->vtable->add_ref == NULL)
|| authority->vtable->ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return authority->vtable->add_ref (authority);
return authority->vtable->ref (authority);
}
int
authority_release (authority_t authority)
void
authority_destroy (authority_t *pauthority)
{
if (authority == NULL || authority->vtable == NULL
|| authority->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return authority->vtable->release (authority);
}
int
authority_destroy (authority_t authority)
{
if (authority == NULL || authority->vtable == NULL
|| authority->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return authority->vtable->destroy (authority);
if (pauthority && *pauthority)
{
authority_t authority = *pauthority;
if (authority->vtable && authority->vtable->destroy)
authority->vtable->destroy (pauthority);
*pauthority = NULL;
}
}
int
......
......@@ -40,7 +40,7 @@ static void
_bs_cleanup (void *arg)
{
struct _bs *bs = arg;
monitor_unlock (bs->lock);
mu_refcount_unlock (bs->refcount);
}
static int
......@@ -61,33 +61,22 @@ refill (struct _bs *bs)
}
static int
_bs_add_ref (stream_t stream)
_bs_ref (stream_t stream)
{
struct _bs *bs = (struct _bs *)stream;
return stream_add_ref (bs->stream);
return mu_refcount_inc (bs->refcount);
}
static int
_bs_destroy (stream_t stream)
{
struct _bs *bs = (struct _bs *)stream;
stream_destroy (bs->stream);
monitor_destroy (bs->lock);
free (bs);
return 0;
}
static int
_bs_release (stream_t stream)
static void
_bs_destroy (stream_t *pstream)
{
struct _bs *bs = (struct _bs *)stream;
int status = stream_release (bs->stream);
if (status == 0)
struct _bs *bs = (struct _bs *)*pstream;
if (mu_refcount_dec (bs->refcount) == 0)
{
_bs_destroy (stream);
return 0;
stream_destroy (&bs->stream);
mu_refcount_destroy (&bs->refcount);
free (bs);
}
return status;
}
static int
......@@ -101,7 +90,7 @@ static int
_bs_close (stream_t stream)
{
struct _bs *bs = (struct _bs *)stream;
monitor_lock (bs->lock);
mu_refcount_lock (bs->refcount);
/* Clear the buffer of any residue left. */
if (bs->rbuffer.base && bs->rbuffer.bufsize)
{
......@@ -109,7 +98,7 @@ _bs_close (stream_t stream)
bs->rbuffer.count = 0;
memset (bs->rbuffer.base, '\0', bs->rbuffer.bufsize);
}
monitor_unlock (bs->lock);
mu_refcount_unlock (bs->refcount);
return stream_close (bs->stream);
}
......@@ -141,7 +130,7 @@ _bs_read (stream_t stream, void *buf, size_t count, size_t *pnread)
char *p = buf;
int r;
monitor_lock (bs->lock);
mu_refcount_lock (bs->refcount);
monitor_cleanup_push (_bs_cleanup, bs);
/* If the amount requested is bigger then the buffer cache size
......@@ -200,7 +189,7 @@ _bs_read (stream_t stream, void *buf, size_t count, size_t *pnread)
*pnread = count;
}
}
monitor_unlock (bs->lock);
mu_refcount_unlock (bs->refcount);
monitor_cleanup_pop (0);
}
return status;
......@@ -234,7 +223,7 @@ _bs_readline (stream_t stream, char *buf, size_t count, size_t *pnread)
size_t len;
size_t total = 0;
monitor_lock (bs->lock);
mu_refcount_lock (bs->refcount);
monitor_cleanup_push (_bs_cleanup, bs);
count--; /* Leave space for the null. */
......@@ -282,7 +271,7 @@ _bs_readline (stream_t stream, char *buf, size_t count, size_t *pnread)
if (pnread)
*pnread = s - buf;
monitor_unlock (bs->lock);
mu_refcount_unlock (bs->refcount);
monitor_cleanup_pop (0);
}
return status;
......@@ -374,8 +363,13 @@ _bs_is_readready (stream_t stream, int timeout)
{
struct _bs *bs = (struct _bs *)stream;
/* Drain our buffer first. */
mu_refcount_lock (bs->refcount);
if (bs->rbuffer.count > 0)
return 1;
{
mu_refcount_unlock (bs->refcount);
return 1;
}
mu_refcount_unlock (bs->refcount);
return stream_is_readready (bs->stream, timeout);
}
......@@ -403,8 +397,7 @@ _bs_is_open (stream_t stream)
static struct _stream_vtable _bs_vtable =
{
_bs_add_ref,
_bs_release,
_bs_ref,
_bs_destroy,
_bs_open,
......@@ -444,11 +437,16 @@ stream_buffer_create (stream_t *pstream, stream_t stream, size_t bufsize)
if (bs == NULL)
return MU_ERROR_NO_MEMORY;
bs->base.vtable = &_bs_vtable;
bs->ref = 1;
mu_refcount_create (&(bs->refcount));
if (bs->refcount == NULL)
{
free (bs);
return MU_ERROR_NO_MEMORY;
}
bs->stream = stream;
bs->rbuffer.bufsize = bufsize;
monitor_create (&(bs->lock));
bs->base.vtable = &_bs_vtable;
*pstream = &bs->base;
return 0;
}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
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 <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <mailutils/error.h>
#include <mailutils/sys/attribute.h>
static int
_da_ref (attribute_t attribute)
{
struct _da *da = (struct _da *)attribute;
return mu_refcount_inc (da->refcount);
}
static void
_da_destroy (attribute_t *pattribute)
{
struct _da *da = (struct _da *)*pattribute;
if (mu_refcount_dec (da->refcount) == 0)
{
mu_refcount_destroy (&da->refcount);
free (da);
}
}
static int
_da_get_flags (attribute_t attribute, int *pflags)
{
struct _da *da = (struct _da *)attribute;
mu_refcount_lock (da->refcount);
if (pflags)
*pflags = da->flags;
mu_refcount_unlock (da->refcount);
return 0;
}
static int
_da_set_flags (attribute_t attribute, int flags)
{
struct _da *da = (struct _da *)attribute;
mu_refcount_lock (da->refcount);
da->flags |= (flags | MU_ATTRIBUTE_MODIFIED);
mu_refcount_unlock (da->refcount);
return 0;
}
static int
_da_unset_flags (attribute_t attribute, int flags)
{
struct _da *da = (struct _da *)attribute;
mu_refcount_lock (da->refcount);
da->flags &= ~flags;
/* If Modified was being unset do not reset it. */
if (!(flags & MU_ATTRIBUTE_MODIFIED))
da->flags |= MU_ATTRIBUTE_MODIFIED;
mu_refcount_unlock (da->refcount);
return 0;
}
static int
_da_clear_flags (attribute_t attribute)
{
struct _da *da = (struct _da *)attribute;
mu_refcount_lock (da->refcount);
da->flags = 0;
mu_refcount_unlock (da->refcount);
return 0;
}
static struct _attribute_vtable _da_vtable =
{
_da_ref,
_da_destroy,
_da_get_flags,
_da_set_flags,
_da_unset_flags,
_da_clear_flags
};
int
attribute_create (attribute_t *pattribute)
{
struct _da *da;
if (pattribute == NULL)
return MU_ERROR_INVALID_PARAMETER;
da = calloc (1, sizeof *da);
if (da == NULL)
return MU_ERROR_NO_MEMORY;
mu_refcount_create (&(da->refcount));
if (da->refcount == NULL)
{
free (da);
return MU_ERROR_NO_MEMORY;
}
da->flags = 0;
da->base.vtable = &_da_vtable;
*pattribute = &da->base;
return 0;
}
......@@ -34,7 +34,7 @@
#include <mailutils/error.h>
#include <mailutils/sys/locker.h>
#include <mailutils/monitor.h>
#include <mailutils/refcount.h>
/* locking flags */
#define MU_DOTLOCK_PID 1
......@@ -50,50 +50,30 @@
struct _dotlock
{
struct _locker base;
monitor_t lock;
mu_refcount_t refcount;
int fd;
int ref;
int refcnt;
char *fname;
int flags;
};
static int
_dotlock_add_ref (locker_t locker)
_dotlock_ref (locker_t locker)
{
int status;
struct _dotlock *dotlock = (struct _dotlock *)locker;
monitor_lock (dotlock->lock);
status = ++dotlock->ref;
monitor_unlock (dotlock->lock);
return status;
return mu_refcount_inc (dotlock->refcount);
}
static int
_dotlock_destroy (locker_t locker)
static void
_dotlock_destroy (locker_t *plocker)
{
struct _dotlock *dotlock = (struct _dotlock *)locker;
free (dotlock->fname);
monitor_destroy (dotlock->lock);
free (dotlock);
return 0;
}
static int
_dotlock_release (locker_t locker)
{
int status;
struct _dotlock *dotlock = (struct _dotlock *)locker;
monitor_lock (dotlock->lock);
status = --dotlock->ref;
if (status <= 0)
struct _dotlock *dotlock = (struct _dotlock *)*plocker;
if (mu_refcount_dec (dotlock->refcount) == 0)
{
monitor_unlock (dotlock->lock);
_dotlock_destroy (locker);
return 0;
mu_refcount_destroy (&dotlock->refcount);
free (dotlock->fname);
free (dotlock);
}
monitor_unlock (dotlock->lock);
return status;
}
static int
......@@ -243,8 +223,7 @@ _dotlock_unlock (locker_t locker)
static struct _locker_vtable _dotlock_vtable =
{
_dotlock_add_ref,
_dotlock_release,
_dotlock_ref,
_dotlock_destroy,
_dotlock_lock,
......@@ -264,6 +243,13 @@ locker_dotlock_create (locker_t *plocker, const char *filename)
if (dotlock == NULL)
return MU_ERROR_NO_MEMORY;
mu_refcount_create (&dotlock->refcount);
if (dotlock->refcount)
{
free (dotlock);
return MU_ERROR_NO_MEMORY;
}
dotlock->fname = calloc (strlen (filename) + 5 /*strlen(".lock")*/ + 1, 1);
if (dotlock->fname == NULL)
{
......@@ -273,11 +259,10 @@ locker_dotlock_create (locker_t *plocker, const char *filename)
strcpy (dotlock->fname, filename);
strcat (dotlock->fname, ".lock");
dotlock->base.vtable = &_dotlock_vtable;
dotlock->flags = MU_DOTLOCK_PID | MU_DOTLOCK_TIME | MU_DOTLOCK_FCNTL;
dotlock->fd = -1;
dotlock->ref = 1;
dotlock->refcnt = 0;
dotlock->base.vtable = &_dotlock_vtable;
*plocker = &dotlock->base;
return 0;
}
......
......@@ -23,55 +23,76 @@
#include <mailutils/sys/envelope.h>
int
(envelope_add_ref) (envelope_t envelope)
envelope_ref (envelope_t envelope)
{
if (envelope == NULL || envelope->vtable == NULL
|| envelope->vtable->add_ref == NULL)
|| envelope->vtable->ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return envelope->vtable->add_ref (envelope);
return envelope->vtable->ref (envelope);
}
void
envelope_destroy (envelope_t *penvelope)
{
if (penvelope && *penvelope)
{
envelope_t envelope = *penvelope;
if (envelope->vtable && envelope->vtable->destroy)
envelope->vtable->destroy (penvelope);
*penvelope = NULL;
}
}
int
envelope_get_sender (envelope_t envelope, address_t *paddr)
{
if (envelope == NULL || envelope->vtable == NULL
|| envelope->vtable->get_sender == NULL)
return MU_ERROR_NOT_SUPPORTED;
return envelope->vtable->get_sender (envelope, paddr);
}
int
(envelope_release) (envelope_t envelope)
envelope_set_sender (envelope_t envelope, address_t addr)
{
if (envelope == NULL || envelope->vtable == NULL
|| envelope->vtable->release == NULL)
|| envelope->vtable->set_sender == NULL)
return MU_ERROR_NOT_SUPPORTED;
return envelope->vtable->release (envelope);
return envelope->vtable->set_sender (envelope, addr);
}
int
(envelope_destroy) (envelope_t envelope)
envelope_get_recipient (envelope_t envelope, address_t *paddr)
{
if (envelope == NULL || envelope->vtable == NULL
|| envelope->vtable->destroy == NULL)
|| envelope->vtable->get_recipient == NULL)
return MU_ERROR_NOT_SUPPORTED;
return envelope->vtable->destroy (envelope);
return envelope->vtable->get_recipient (envelope, paddr);
}
int
(envelope_sender) (envelope_t envelope, address_t *paddr)
envelope_set_recipient (envelope_t envelope, address_t addr)
{
if (envelope == NULL || envelope->vtable == NULL
|| envelope->vtable->sender == NULL)
|| envelope->vtable->set_recipient == NULL)
return MU_ERROR_NOT_SUPPORTED;
return envelope->vtable->sender (envelope, paddr);
return envelope->vtable->set_recipient (envelope, addr);
}
int
(envelope_recipient) (envelope_t envelope, address_t *paddr)
envelope_get_date (envelope_t envelope, struct tm *tm, struct mu_timezone *tz)
{
if (envelope == NULL || envelope->vtable == NULL
|| envelope->vtable->recipient == NULL)
|| envelope->vtable->get_date == NULL)
return MU_ERROR_NOT_SUPPORTED;
return envelope->vtable->recipient (envelope, paddr);
return envelope->vtable->get_date (envelope, tm, tz);
}
int
(envelope_date) (envelope_t envelope, struct tm *tm, struct mu_timezone *tz)
envelope_set_date (envelope_t envelope, struct tm *tm, struct mu_timezone *tz)
{
if (envelope == NULL || envelope->vtable == NULL
|| envelope->vtable->date == NULL)
|| envelope->vtable->set_date == NULL)
return MU_ERROR_NOT_SUPPORTED;
return envelope->vtable->date (envelope, tm, tz);
return envelope->vtable->set_date (envelope, tm, tz);
}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Library General Public License
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 <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <mailutils/sys/fdstream.h>
#include <mailutils/monitor.h>
#include <mailutils/error.h>
static void
_fds_cleanup (void *arg)
{
struct _fds *fds = arg;
mu_refcount_unlock (fds->refcount);
}
static int
_fds_ref (stream_t stream)
{
struct _fds *fds = (struct _fds *)stream;
return mu_refcount_inc (fds->refcount);
}
static void
_fds_destroy (stream_t *pstream)
{
struct _fds *fds = (struct _fds *)*pstream;
if (mu_refcount_dec (fds->refcount) == 0)
{
if (fds->fd != -1)
close (fds->fd);
mu_refcount_destroy (&fds->refcount);
free (fds);
}
}
static int
_fds_close0 (stream_t stream)
{
struct _fds *fds = (struct _fds *)stream;
if (fds->fd != -1)
close (fds->fd);
fds->fd = -1;
return 0;
}
static int
_fds_close (stream_t stream)
{
struct _fds *fds = (struct _fds *)stream;
mu_refcount_lock (fds->refcount);
monitor_cleanup_push (_fds_cleanup, fds);
_fds_close0 (stream);
mu_refcount_unlock (fds->refcount);
monitor_cleanup_pop (0);
return 0;
}
static int
_fds_open (stream_t stream, const char *name, int port, int flags)
{
(void)stream; (void)name; (void)port; (void)flags;
return MU_ERROR_NOT_SUPPORTED;
}
static int
_fds_get_fd (stream_t stream, int *fd)
{
struct _fds *fds = (struct _fds *)stream;
if (fd == NULL || fds->fd == -1)
return MU_ERROR_INVALID_PARAMETER;
*fd = fds->fd;
return 0;
}
static int
_fds_read (stream_t stream, void *buf, size_t buf_size, size_t *br)
{
struct _fds *fds = (struct _fds *)stream;
int bytes = 0;
int status = 0;
bytes = read (fds->fd, buf, buf_size);
if (bytes == -1)
{
bytes = 0;
status = errno;
}
if (br)
*br = bytes;
return status;
}
static int
_fds_readline (stream_t stream, char *buf, size_t buf_size, size_t *br)
{
struct _fds *fds = (struct _fds *)stream;
int status = 0;
size_t n;
int nr = 0;
char c;
/* Grossly inefficient hopefully they override this */
for (n = 1; n < buf_size; n++)
{
nr = read (fds->fd, &c, 1);
if (nr == -1) /* Error. */
{
status = errno;
break;
}
else if (nr == 1)
{
*buf++ = c;
if (c == '\n') /* Newline is stored like fgets(). */
break;
}
else if (nr == 0)
{
if (n == 1) /* EOF, no data read. */
n = 0;
break; /* EOF, some data was read. */
}
}
*buf = '\0';
if (br)
*br = (n == buf_size) ? n - 1: n;
return status;
}
static int
_fds_write (stream_t stream, const void *buf, size_t buf_size, size_t *bw)
{
struct _fds *fds = (struct _fds *)stream;
int bytes = 0;
int status = 0;
bytes = write (fds->fd, buf, buf_size);
if (bytes == -1)
{
bytes = 0;
status = errno;
}
if (bw)
*bw = bytes;
return status;
}
static int
_fds_seek (stream_t stream, off_t off, enum stream_whence whence)
{
struct _fds *fds = (struct _fds *)stream;
int err = 0;
if (fds->fd)
{
if (whence == MU_STREAM_WHENCE_SET)
off = lseek (fds->fd, off, SEEK_SET);
else if (whence == MU_STREAM_WHENCE_CUR)
off = lseek (fds->fd, off, SEEK_CUR);
else if (whence == MU_STREAM_WHENCE_END)
off = lseek (fds->fd, off, SEEK_END);
else
err = MU_ERROR_INVALID_PARAMETER;
if (err == -1)
err = errno;
}
return err;
}
static int
_fds_tell (stream_t stream, off_t *off)
{
struct _fds *fds = (struct _fds *)stream;
int err = 0;
if (off)
{
*off = lseek (fds->fd, 0, SEEK_CUR);
if (*off == -1)
{
err = errno;
*off = 0;
}
}
return err;;
}
static int
_fds_get_size (stream_t stream, off_t *psize)
{
struct _fds *fds = (struct _fds *)stream;
struct stat stbuf;
int err = 0;
stbuf.st_size = 0;
if (fstat (fds->fd, &stbuf) == -1)
err = errno;
if (psize)
*psize = stbuf.st_size;
return err;
}
static int
_fds_truncate (stream_t stream, off_t len)
{
struct _fds *fds = (struct _fds *)stream;
int err = 0;
if (ftruncate (fds->fd, len) == -1)
err = errno ;
return err;
}
static int
_fds_flush (stream_t stream)
{
(void)stream;
return 0;
}
static int
_fds_get_flags (stream_t stream, int *flags)
{
struct _fds *fds = (struct _fds *)stream;
if (flags == NULL)
return MU_ERROR_INVALID_PARAMETER;
*flags = fds->flags;
return 0;
}
static int
_fds_get_state (stream_t stream, enum stream_state *state)
{
(void)stream;
if (state == NULL)
return MU_ERROR_INVALID_PARAMETER;
*state = MU_STREAM_NO_STATE;
return 0;
}
static int
_fds_is_readready (stream_t stream, int timeout)
{
struct _fds *fds = (struct _fds *)stream;
int ready;
struct timeval tv;
fd_set fset;
FD_ZERO (&fset);
FD_SET (fds->fd, &fset);
tv.tv_sec = timeout / 100;
tv.tv_usec = (timeout % 1000) * 1000;
ready = select (fds->fd + 1, &fset, NULL, NULL, (timeout == -1) ? NULL: &tv);
return (ready == -1) ? 0 : 1;
}
static int
_fds_is_writeready (stream_t stream, int timeout)
{
struct _fds *fds = (struct _fds *)stream;
int ready;
struct timeval tv;
fd_set fset;
FD_ZERO (&fset);
FD_SET (fds->fd, &fset);
tv.tv_sec = timeout / 100;
tv.tv_usec = (timeout % 1000) * 1000;
ready = select (fds->fd + 1, NULL, &fset, NULL, (timeout == -1) ? NULL: &tv);
return (ready == -1) ? 0 : 1;
}
static int
_fds_is_exceptionpending (stream_t stream, int timeout)
{
struct _fds *fds = (struct _fds *)stream;
int ready;
struct timeval tv;
fd_set fset;
FD_ZERO (&fset);
FD_SET (fds->fd, &fset);
tv.tv_sec = timeout / 100;
tv.tv_usec = (timeout % 1000) * 1000;
ready = select (fds->fd + 1, NULL, NULL, &fset, (timeout == -1) ? NULL: &tv);
return (ready == -1) ? 0 : 1;
}
static int
_fds_is_open (stream_t stream)
{
struct _fds *fds = (struct _fds *)stream;
return fds->fd >= 0;
}
static struct _stream_vtable _fds_vtable =
{
_fds_ref,
_fds_destroy,
_fds_open,
_fds_close,
_fds_read,
_fds_readline,
_fds_write,
_fds_seek,
_fds_tell,
_fds_get_size,
_fds_truncate,
_fds_flush,
_fds_get_fd,
_fds_get_flags,
_fds_get_state,
_fds_is_readready,
_fds_is_writeready,
_fds_is_exceptionpending,
_fds_is_open
};
int
stream_fd_create (stream_t *pstream, int fd)
{
struct _fds *fds;
if (pstream == NULL || fd < 0)
return MU_ERROR_INVALID_PARAMETER;
fds = calloc (1, sizeof *fds);
if (fds == NULL)
return MU_ERROR_NO_MEMORY;
mu_refcount_create (&fds->refcount);
if (fds->refcount == NULL)
{
free (fds);
return MU_ERROR_NO_MEMORY;
}
fds->fd = fd;
fds->base.vtable = &_fds_vtable;
*pstream = &fds->base;
return 0;
}
......@@ -20,30 +20,24 @@
#include <mailutils/sys/folder.h>
int
folder_add_ref (folder_t folder)
folder_ref (folder_t folder)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->add_ref == NULL)
|| folder->vtable->ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->add_ref (folder);
return folder->vtable->ref (folder);
}
int
folder_release (folder_t folder)
void
folder_destroy (folder_t *pfolder)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->release (folder);
}
int
folder_destroy (folder_t folder)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->destroy (folder);
if (pfolder && *pfolder)
{
folder_t folder = *pfolder;
if (folder->vtable && folder->vtable->destroy)
folder->vtable->destroy (pfolder);
*pfolder = NULL;
}
}
int
......
......@@ -35,42 +35,23 @@
static int
_fs_add_ref (stream_t stream)
_fs_ref (stream_t stream)
{
struct _fs *fs = (struct _fs *)stream;
int status;
monitor_lock (fs->lock);
status = ++fs->ref;
monitor_unlock (fs->lock);
return status;
}
static int
_fs_destroy (stream_t stream)
{
struct _fs *fs = (struct _fs *)stream;
if (fs->file)
fclose (fs->file);
monitor_destroy (fs->lock);
free (fs);
return 0;
return mu_refcount_inc (fs->refcount);
}
static int
_fs_release (stream_t stream)
static void
_fs_destroy (stream_t *pstream)
{
int status;
struct _fs *fs = (struct _fs *)stream;
monitor_lock (fs->lock);
status = --fs->ref;
if (status <= 0)
struct _fs *fs = (struct _fs *)*pstream;
if (mu_refcount_dec (fs->refcount) == 0)
{
monitor_unlock (fs->lock);
_fs_destroy (stream);
return 0;
if (fs->file)
fclose (fs->file);
mu_refcount_destroy (&fs->refcount);
free (fs);
}
monitor_unlock (fs->lock);
return status;
}
static int
......@@ -201,7 +182,6 @@ _fs_seek (stream_t stream, off_t off, enum stream_whence whence)
int err = 0;
if (fs->file)
{
errno = MU_ERROR_INVALID_PARAMETER;
if (whence == MU_STREAM_WHENCE_SET)
err = fseek (fs->file, off, SEEK_SET);
else if (whence == MU_STREAM_WHENCE_CUR)
......@@ -210,7 +190,7 @@ _fs_seek (stream_t stream, off_t off, enum stream_whence whence)
err = fseek (fs->file, off, SEEK_END);
else
err = MU_ERROR_INVALID_PARAMETER;
if (err != 0)
if (err == -1)
err = errno;
}
return err;
......@@ -395,8 +375,7 @@ _fs_open (stream_t stream, const char *filename, int port, int flags)
static struct _stream_vtable _fs_vtable =
{
_fs_add_ref,
_fs_release,
_fs_ref,
_fs_destroy,
_fs_open,
......@@ -436,11 +415,40 @@ stream_file_create (stream_t *pstream)
if (fs == NULL)
return MU_ERROR_NO_MEMORY ;
fs->base.vtable = &_fs_vtable;
fs->ref = 1;
mu_refcount_create (&fs->refcount);
if (fs->refcount == NULL)
{
free (fs);
return MU_ERROR_NO_MEMORY ;
}
fs->file = NULL;
fs->flags = 0;
monitor_create (&(fs->lock));
fs->base.vtable = &_fs_vtable;
*pstream = &fs->base;
return 0;
}
int
stream_stdio_create (stream_t *pstream, FILE *fp)
{
struct _fs *fs;
if (pstream == NULL)
return MU_ERROR_INVALID_PARAMETER;
fs = calloc (1, sizeof *fs);
if (fs == NULL)
return MU_ERROR_NO_MEMORY ;
mu_refcount_create (&fs->refcount);
if (fs->refcount == NULL)
{
free (fs);
return MU_ERROR_NO_MEMORY ;
}
fs->file = fp;
fs->flags = 0;
fs->base.vtable = &_fs_vtable;
*pstream = &fs->base;
return 0;
}
......
......@@ -26,34 +26,28 @@
#include <mailutils/sys/header.h>
int
(header_add_ref) (header_t header)
header_ref (header_t header)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->add_ref == NULL)
|| header->vtable->ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return header->vtable->add_ref (header);
return header->vtable->ref (header);
}
int
(header_release) (header_t header)
void
header_destroy (header_t *pheader)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return header->vtable->release (header);
}
int
(header_destroy) (header_t header)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return header->vtable->destroy (header);
if (pheader && *pheader)
{
header_t header = *pheader;
if (header->vtable && header->vtable->destroy)
header->vtable->destroy (pheader);
*pheader = NULL;
}
}
int
(header_is_modified) (header_t header)
header_is_modified (header_t header)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->is_modified == NULL)
......@@ -62,7 +56,7 @@ int
}
int
(header_clear_modified) (header_t header)
header_clear_modified (header_t header)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->clear_modified == NULL)
......@@ -71,8 +65,7 @@ int
}
int
(header_set_value) (header_t header, const char *fn, const char *fv,
int replace)
header_set_value (header_t header, const char *fn, const char *fv, int replace)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->set_value == NULL)
......@@ -81,8 +74,8 @@ int
}
int
(header_get_value) (header_t header, const char *name, char *buffer,
size_t buflen, size_t *pn)
header_get_value (header_t header, const char *name, char *buffer,
size_t buflen, size_t *pn)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->get_value == NULL)
......@@ -108,7 +101,7 @@ header_aget_value (header_t header, const char *name, char **pvalue)
}
int
(header_get_field_count) (header_t header, size_t *pcount)
header_get_field_count (header_t header, size_t *pcount)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->get_field_count == NULL)
......@@ -117,8 +110,8 @@ int
}
int
(header_get_field_name) (header_t header, size_t num, char *buf,
size_t buflen, size_t *pn)
header_get_field_name (header_t header, size_t num, char *buf,
size_t buflen, size_t *pn)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->get_field_name == NULL)
......@@ -144,8 +137,8 @@ header_aget_field_name (header_t header, size_t num, char **pvalue)
}
int
(header_get_field_value) (header_t header, size_t num, char *buf,
size_t buflen, size_t *pn)
header_get_field_value (header_t header, size_t num, char *buf,
size_t buflen, size_t *pn)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->get_field_value == NULL)
......@@ -171,7 +164,7 @@ header_aget_field_value (header_t header, size_t num, char **pvalue)
}
int
(header_get_lines) (header_t header, size_t *plines)
header_get_lines (header_t header, size_t *plines)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->get_lines == NULL)
......@@ -180,7 +173,7 @@ int
}
int
(header_get_size) (header_t header, size_t *psize)
header_get_size (header_t header, size_t *psize)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->get_size == NULL)
......@@ -189,7 +182,7 @@ int
}
int
(header_get_stream) (header_t header, stream_t *pstream)
header_get_stream (header_t header, stream_t *pstream)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->get_stream == NULL)
......
......@@ -27,6 +27,7 @@ pkginclude_HEADERS = \
parse822.h \
pop3.h \
property.h \
refcount.h \
stream.h \
ticket.h \
url.h
......
......@@ -35,11 +35,10 @@ extern "C" {
struct _address;
typedef struct _address *address_t;
extern int address_create __P ((address_t *, const char *));
extern int address_create __P ((address_t *, const char *));
extern int address_add_ref __P ((address_t));
extern int address_release __P ((address_t));
extern int address_destroy __P ((address_t));
extern int address_ref __P ((address_t));
extern void address_destroy __P ((address_t *));
extern int address_get_email
__P ((address_t, size_t, char *, size_t, size_t *));
......
......@@ -42,47 +42,46 @@ typedef struct _attribute * attribute_t;
#define MU_ATTRIBUTE_MODIFIED 0x1000
#define MU_ATTRIBUTE_RECENT 0x0000
extern int attribute_create __P ((attribute_t *));
extern int attribute_add_ref __P ((attribute_t));
extern int attribute_release __P ((attribute_t));
extern int attribute_destroy __P ((attribute_t));
extern int attribute_is_seen __P ((attribute_t));
extern int attribute_is_answered __P ((attribute_t));
extern int attribute_is_flagged __P ((attribute_t));
extern int attribute_is_deleted __P ((attribute_t));
extern int attribute_is_draft __P ((attribute_t));
extern int attribute_is_recent __P ((attribute_t));
extern int attribute_is_read __P ((attribute_t));
extern int attribute_is_modified __P ((attribute_t));
extern int attribute_set_seen __P ((attribute_t));
extern int attribute_set_answered __P ((attribute_t));
extern int attribute_set_flagged __P ((attribute_t));
extern int attribute_set_deleted __P ((attribute_t));
extern int attribute_set_draft __P ((attribute_t));
extern int attribute_set_recent __P ((attribute_t));
extern int attribute_set_read __P ((attribute_t));
extern int attribute_set_modified __P ((attribute_t));
extern int attribute_unset_seen __P ((attribute_t));
extern int attribute_unset_answered __P ((attribute_t));
extern int attribute_unset_flagged __P ((attribute_t));
extern int attribute_unset_deleted __P ((attribute_t));
extern int attribute_unset_draft __P ((attribute_t));
extern int attribute_unset_recent __P ((attribute_t));
extern int attribute_unset_read __P ((attribute_t));
extern int attribute_unset_modified __P ((attribute_t));
extern int attribute_get_flags __P ((attribute_t, int *));
extern int attribute_set_flags __P ((attribute_t, int));
extern int attribute_unset_flags __P ((attribute_t, int));
extern int attribute_clear_flags __P ((attribute_t));
extern int attribute_is_equal __P ((attribute_t, attribute_t));
extern int attribute_copy __P ((attribute_t dst, attribute_t src));
extern int attribute_create __P ((attribute_t *));
extern int attribute_ref __P ((attribute_t));
extern void attribute_destroy __P ((attribute_t *));
extern int attribute_is_seen __P ((attribute_t));
extern int attribute_is_answered __P ((attribute_t));
extern int attribute_is_flagged __P ((attribute_t));
extern int attribute_is_deleted __P ((attribute_t));
extern int attribute_is_draft __P ((attribute_t));
extern int attribute_is_recent __P ((attribute_t));
extern int attribute_is_read __P ((attribute_t));
extern int attribute_is_modified __P ((attribute_t));
extern int attribute_set_seen __P ((attribute_t));
extern int attribute_set_answered __P ((attribute_t));
extern int attribute_set_flagged __P ((attribute_t));
extern int attribute_set_deleted __P ((attribute_t));
extern int attribute_set_draft __P ((attribute_t));
extern int attribute_set_recent __P ((attribute_t));
extern int attribute_set_read __P ((attribute_t));
extern int attribute_set_modified __P ((attribute_t));
extern int attribute_unset_seen __P ((attribute_t));
extern int attribute_unset_answered __P ((attribute_t));
extern int attribute_unset_flagged __P ((attribute_t));
extern int attribute_unset_deleted __P ((attribute_t));
extern int attribute_unset_draft __P ((attribute_t));
extern int attribute_unset_recent __P ((attribute_t));
extern int attribute_unset_read __P ((attribute_t));
extern int attribute_unset_modified __P ((attribute_t));
extern int attribute_get_flags __P ((attribute_t, int *));
extern int attribute_set_flags __P ((attribute_t, int));
extern int attribute_unset_flags __P ((attribute_t, int));
extern int attribute_clear_flags __P ((attribute_t));
extern int attribute_is_equal __P ((attribute_t, attribute_t));
extern int attribute_copy __P ((attribute_t dst, attribute_t src));
#ifdef __cplusplus
......
......@@ -37,12 +37,11 @@ extern "C" {
struct _authority;
typedef struct _authority *authority_t;
extern int authority_add_ref __P ((authority_t));
extern int authority_release __P ((authority_t));
extern int authority_destroy __P ((authority_t));
extern int authority_set_ticket __P ((authority_t, ticket_t));
extern int authority_get_ticket __P ((authority_t, ticket_t *));
extern int authority_authenticate __P ((authority_t));
extern int authority_ref __P ((authority_t));
extern void authority_destroy __P ((authority_t *));
extern int authority_set_ticket __P ((authority_t, ticket_t));
extern int authority_get_ticket __P ((authority_t, ticket_t *));
extern int authority_authenticate __P ((authority_t));
extern int authority_userpass_create __P ((authority_t *));
......
......@@ -38,19 +38,19 @@ extern "C" {
struct _body;
typedef struct _body *body_t;
extern int body_add_ref __P ((body_t));
extern int body_release __P ((body_t));
extern int body_destroy __P ((body_t));
extern int body_ref __P ((body_t));
extern void body_release __P ((body_t *));
extern int body_destroy __P ((body_t));
extern int body_is_modified __P ((body_t));
extern int body_clear_modified __P ((body_t));
extern int body_is_modified __P ((body_t));
extern int body_clear_modified __P ((body_t));
extern int body_get_stream __P ((body_t, stream_t *));
extern int body_get_stream __P ((body_t, stream_t *));
extern int body_get_property __P ((body_t, property_t *));
extern int body_get_property __P ((body_t, property_t *));
extern int body_get_size __P ((body_t, size_t*));
extern int body_get_lines __P ((body_t, size_t *));
extern int body_get_size __P ((body_t, size_t*));
extern int body_get_lines __P ((body_t, size_t *));
#ifdef __cplusplus
}
......
......@@ -38,16 +38,15 @@ typedef struct _debug* mu_debug_t;
#define MU_DEBUG_TRACE 1
#define MU_DEBUG_PROT 2
extern int mu_debug_add_ref __P ((mu_debug_t));
extern int mu_debug_release __P ((mu_debug_t));
extern int mu_debug_destroy __P ((mu_debug_t));
extern int mu_debug_set_level __P ((mu_debug_t, size_t level));
extern int mu_debug_get_level __P ((mu_debug_t, size_t *plevel));
extern int mu_debug_print __P ((mu_debug_t debug, size_t level,
const char *format, ...));
extern int mu_debug_printv __P ((mu_debug_t debug, size_t level,
const char *format, va_list argp));
extern int mu_debug_stderr_create __P ((mu_debug_t *));
extern int mu_debug_ref __P ((mu_debug_t));
extern void mu_debug_destroy __P ((mu_debug_t *));
extern int mu_debug_set_level __P ((mu_debug_t, size_t level));
extern int mu_debug_get_level __P ((mu_debug_t, size_t *plevel));
extern int mu_debug_print __P ((mu_debug_t debug, size_t level,
const char *format, ...));
extern int mu_debug_printv __P ((mu_debug_t debug, size_t level,
const char *format, va_list argp));
extern int mu_debug_stderr_create __P ((mu_debug_t *));
#ifdef __cplusplus
}
......
......@@ -36,13 +36,15 @@ extern "C" {
struct _envelope;
typedef struct _envelope *envelope_t;
extern int envelope_add_ref __P ((envelope_t));
extern int envelope_release __P ((envelope_t));
extern int envelope_destroy __P ((envelope_t));
extern int envelope_sender __P ((envelope_t, address_t *));
extern int envelope_recipient __P ((envelope_t, address_t *));
extern int envelope_date __P ((envelope_t, struct tm *, struct mu_timezone *));
extern int envelope_ref __P ((envelope_t));
extern void envelope_destroy __P ((envelope_t *));
extern int envelope_get_sender __P ((envelope_t, address_t *));
extern int envelope_set_sender __P ((envelope_t, address_t));
extern int envelope_get_recipient __P ((envelope_t, address_t *));
extern int envelope_set_recipient __P ((envelope_t, address_t));
extern int envelope_get_date __P ((envelope_t, struct tm *, struct mu_timezone *));
extern int envelope_set_date __P ((envelope_t, struct tm *, struct mu_timezone *));
#ifdef __cplusplus
}
......
......@@ -54,23 +54,22 @@ struct list_response
char *name;
};
extern int folder_create __P ((folder_t *, const char *));
extern int folder_add_ref __P ((folder_t));
extern int folder_release __P ((folder_t));
extern int folder_destroy __P ((folder_t));
extern int folder_open __P ((folder_t, int flag));
extern int folder_close __P ((folder_t));
extern int folder_delete __P ((folder_t, const char *));
extern int folder_rename __P ((folder_t, const char *, const char *));
extern int folder_subscribe __P ((folder_t, const char *));
extern int folder_unsubscribe __P ((folder_t, const char *));
extern int folder_list __P ((folder_t, const char *, const char *,
iterator_t *));
extern int folder_lsub __P ((folder_t, const char *, const char *,
iterator_t *));
extern int folder_create __P ((folder_t *, const char *));
extern int folder_ref __P ((folder_t));
extern void folder_destroy __P ((folder_t *));
extern int folder_open __P ((folder_t, int));
extern int folder_close __P ((folder_t));
extern int folder_delete __P ((folder_t, const char *));
extern int folder_rename __P ((folder_t, const char *, const char *));
extern int folder_subscribe __P ((folder_t, const char *));
extern int folder_unsubscribe __P ((folder_t, const char *));
extern int folder_list __P ((folder_t, const char *, const char *,
iterator_t *));
extern int folder_lsub __P ((folder_t, const char *, const char *,
iterator_t *));
/* Stream settings. */
extern int folder_get_stream __P ((folder_t, stream_t *));
......
......@@ -77,36 +77,35 @@ extern "C" {
struct _header;
typedef struct _header * header_t;
extern int header_add_ref __P ((header_t));
extern int header_release __P ((header_t));
extern int header_destroy __P ((header_t));
extern int header_ref __P ((header_t));
extern void header_destroy __P ((header_t *));
extern int header_is_modified __P ((header_t));
extern int header_clear_modified __P ((header_t));
extern int header_is_modified __P ((header_t));
extern int header_clear_modified __P ((header_t));
extern int header_set_value __P ((header_t, const char *,
extern int header_set_value __P ((header_t, const char *,
const char *, int));
extern int header_get_value __P ((header_t, const char *, char *,
size_t, size_t *));
extern int header_aget_value __P ((header_t, const char *, char **));
extern int header_get_value __P ((header_t, const char *, char *,
size_t, size_t *));
extern int header_aget_value __P ((header_t, const char *, char **));
extern int header_get_field_count __P ((header_t, size_t *));
extern int header_get_field_value __P ((header_t, size_t, char *,
size_t, size_t *));
extern int header_aget_field_value __P ((header_t, size_t, char **));
extern int header_get_field_name __P ((header_t, size_t, char *,
size_t, size_t *));
extern int header_aget_field_name __P ((header_t, size_t, char **));
extern int header_get_field_count __P ((header_t, size_t *));
extern int header_get_field_value __P ((header_t, size_t, char *,
size_t, size_t *));
extern int header_aget_field_value __P ((header_t, size_t, char **));
extern int header_get_field_name __P ((header_t, size_t, char *,
size_t, size_t *));
extern int header_aget_field_name __P ((header_t, size_t, char **));
extern int header_get_stream __P ((header_t, stream_t *));
extern int header_set_stream __P ((header_t, stream_t, void *));
extern int header_get_stream __P ((header_t, stream_t *));
extern int header_set_stream __P ((header_t, stream_t, void *));
extern int header_get_size __P ((header_t, size_t *));
extern int header_get_size __P ((header_t, size_t *));
extern int header_get_lines __P ((header_t, size_t *));
extern int header_get_lines __P ((header_t, size_t *));
extern int header_create __P ((header_t *, const char *, size_t));
extern int header_create __P ((header_t *, const char *, size_t));
#ifdef __cplusplus
......
......@@ -33,14 +33,13 @@ extern "C" {
struct _iterator;
typedef struct _iterator *iterator_t;
extern int iterator_add_ref __P ((iterator_t));
extern int iterator_destroy __P ((iterator_t));
extern int iterator_release __P ((iterator_t));
extern int iterator_first __P ((iterator_t));
extern int iterator_next __P ((iterator_t));
extern int iterator_current __P ((iterator_t, void *));
extern int iterator_is_done __P ((iterator_t));
extern int iterator_ref __P ((iterator_t));
extern void iterator_destroy __P ((iterator_t *));
extern int iterator_first __P ((iterator_t));
extern int iterator_next __P ((iterator_t));
extern int iterator_current __P ((iterator_t, void *));
extern int iterator_is_done __P ((iterator_t));
#ifdef __cplusplus
}
......
......@@ -36,15 +36,16 @@ extern "C" {
struct _list;
typedef struct _list *mu_list_t;
extern int mu_list_create __P ((mu_list_t *));
extern int mu_list_destroy __P ((mu_list_t));
extern int mu_list_append __P ((mu_list_t, void *));
extern int mu_list_prepend __P ((mu_list_t, void *));
extern int mu_list_is_empty __P ((mu_list_t));
extern int mu_list_count __P ((mu_list_t, size_t *));
extern int mu_list_remove __P ((mu_list_t, void *));
extern int mu_list_get __P ((mu_list_t, size_t, void **));
extern int mu_list_get_iterator __P ((mu_list_t, iterator_t *));
extern int mu_list_create __P ((mu_list_t *));
extern int mu_list_ref __P ((mu_list_t));
extern void mu_list_destroy __P ((mu_list_t *));
extern int mu_list_append __P ((mu_list_t, void *));
extern int mu_list_prepend __P ((mu_list_t, void *));
extern int mu_list_is_empty __P ((mu_list_t));
extern int mu_list_count __P ((mu_list_t, size_t *));
extern int mu_list_remove __P ((mu_list_t, void *));
extern int mu_list_get __P ((mu_list_t, size_t, void **));
extern int mu_list_get_iterator __P ((mu_list_t, iterator_t *));
#ifdef __cplusplus
}
......
......@@ -35,16 +35,15 @@ extern "C" {
struct _locker;
typedef struct _locker *locker_t;
extern int locker_add_ref __P ((locker_t));
extern int locker_release __P ((locker_t));
extern int locker_destroy __P ((locker_t));
extern int locker_ref __P ((locker_t));
extern void locker_destroy __P ((locker_t *));
extern int locker_lock __P ((locker_t));
extern int locker_touchlock __P ((locker_t));
extern int locker_unlock __P ((locker_t));
extern int locker_lock __P ((locker_t));
extern int locker_touchlock __P ((locker_t));
extern int locker_unlock __P ((locker_t));
extern int locker_dotlock_create __P ((locker_t *, const char *filename));
extern int locker_nfslock_create __P ((locker_t *, const char *filename));
extern int locker_dotlock_create __P ((locker_t *, const char *filename));
extern int locker_nfslock_create __P ((locker_t *, const char *filename));
#ifdef __cplusplus
}
......
......@@ -46,52 +46,51 @@ extern "C" {
#endif /*__P */
/* Constructor/destructor and possible types. */
extern int mailbox_add_ref __P ((mailbox_t));
extern int mailbox_release __P ((mailbox_t));
extern int mailbox_destroy __P ((mailbox_t));
extern int mailbox_get_folder __P ((mailbox_t, folder_t *));
extern int mailbox_ref __P ((mailbox_t));
extern void mailbox_destroy __P ((mailbox_t *));
extern int mailbox_get_folder __P ((mailbox_t, folder_t *));
extern int mailbox_open __P ((mailbox_t, int flag));
extern int mailbox_close __P ((mailbox_t));
extern int mailbox_uidvalidity __P ((mailbox_t, unsigned long *));
extern int mailbox_uidnext __P ((mailbox_t, size_t *));
extern int mailbox_open __P ((mailbox_t, int));
extern int mailbox_close __P ((mailbox_t));
extern int mailbox_uidvalidity __P ((mailbox_t, unsigned long *));
extern int mailbox_uidnext __P ((mailbox_t, size_t *));
/* Messages. */
extern int mailbox_get_message __P ((mailbox_t, size_t msgno, message_t *));
extern int mailbox_append_message __P ((mailbox_t, message_t));
extern int mailbox_messages_count __P ((mailbox_t, size_t *));
extern int mailbox_messages_recent __P ((mailbox_t, size_t *));
extern int mailbox_messages_unseen __P ((mailbox_t, size_t *));
extern int mailbox_expunge __P ((mailbox_t));
extern int mailbox_save_attributes __P ((mailbox_t));
extern int mailbox_get_message __P ((mailbox_t, size_t, message_t *));
extern int mailbox_append_message __P ((mailbox_t, message_t));
extern int mailbox_messages_count __P ((mailbox_t, size_t *));
extern int mailbox_messages_recent __P ((mailbox_t, size_t *));
extern int mailbox_messages_unseen __P ((mailbox_t, size_t *));
extern int mailbox_expunge __P ((mailbox_t));
extern int mailbox_save_attributes __P ((mailbox_t));
/* Update and scanning. */
extern int mailbox_get_size __P ((mailbox_t, off_t *size));
extern int mailbox_is_updated __P ((mailbox_t));
extern int mailbox_scan __P ((mailbox_t, size_t no, size_t *count));
extern int mailbox_get_size __P ((mailbox_t, off_t *));
extern int mailbox_is_updated __P ((mailbox_t));
extern int mailbox_scan __P ((mailbox_t, size_t, size_t *));
/* Mailbox Stream. */
extern int mailbox_get_stream __P ((mailbox_t, stream_t *));
extern int mailbox_get_stream __P ((mailbox_t, stream_t *));
/* Authentication. */
extern int mailbox_get_authority __P ((mailbox_t, authority_t *));
extern int mailbox_set_authority __P ((mailbox_t, authority_t));
extern int mailbox_get_authority __P ((mailbox_t, authority_t *));
extern int mailbox_set_authority __P ((mailbox_t, authority_t));
/* Property. */
extern int mailbox_get_property __P ((mailbox_t, property_t *));
extern int mailbox_get_property __P ((mailbox_t, property_t *));
/* URL. */
extern int mailbox_get_url __P ((mailbox_t, url_t *));
extern int mailbox_get_url __P ((mailbox_t, url_t *));
/* For any debuging */
extern int mailbox_get_debug __P ((mailbox_t, mu_debug_t *));
extern int mailbox_set_debug __P ((mailbox_t, mu_debug_t));
extern int mailbox_get_debug __P ((mailbox_t, mu_debug_t *));
extern int mailbox_set_debug __P ((mailbox_t, mu_debug_t));
/* Events. */
extern int mailbox_get_observable __P ((mailbox_t, observable_t *));
extern int mailbox_get_observable __P ((mailbox_t, observable_t *));
extern int mailbox_create __P ((mailbox_t *, const char *));
extern int mailbox_create_default __P ((mailbox_t *, const char *));
extern int mailbox_create __P ((mailbox_t *, const char *));
extern int mailbox_create_default __P ((mailbox_t *, const char *));
#ifdef __cplusplus
}
......
......@@ -18,8 +18,8 @@
#ifndef _MAILUTILS_MBOX_H
#define _MAILUTILS_MBOX_H
#include <mailutils/message.h>
#include <mailutils/observable.h>
#include <mailutils/stream.h>
#include <mailutils/attribute.h>
#ifdef __cplusplus
extern "C" {
......@@ -37,33 +37,49 @@ struct _mbox;
typedef struct _mbox *mbox_t;
extern int mbox_create __P ((mbox_t *));
extern int mbox_destroy __P ((mbox_t));
extern int mbox_create __P ((mbox_t *));
extern void mbox_destroy __P ((mbox_t *));
extern int mbox_uidvalidity __P ((mbox_t, unsigned long *));
extern int mbox_uidnext __P ((mbox_t, unsigned long));
extern int mbox_get_uidvalidity __P ((mbox_t, unsigned long *));
extern int mbox_get_uidnext __P ((mbox_t, unsigned long));
extern int mbox_open __P ((mbox_t, const char *, int));
extern int mbox_close __P ((mbox_t));
extern int mbox_open __P ((mbox_t, const char *, int));
extern int mbox_close __P ((mbox_t));
extern int mbox_get_message __P ((mbox_t, unsigned int, message_t *));
extern int mbox_get_envelope __P ((mbox_t, unsigned int, envelope_t *));
extern int mbox_get_header __P ((mbox_t, unsigned int, header_t *));
extern int mbox_get_body __P ((mbox_t, unsigned int, body_t *));
extern int mbox_get_attribute __P ((mbox_t, unsigned int, attribute_t *));
extern int mbox_get_uid __P ((mbox_t, unsigned int, unsigned long *));
extern int mbox_get_flags __P ((mbox_t, unsigned int, int *));
extern int mbox_get_separator __P ((mbox_t, unsigned int, char **));
extern int mbox_set_separator __P ((mbox_t, unsigned int, const char *));
extern int mbox_get_size __P ((mbox_t, unsigned long *));
extern int mbox_get_hstream __P ((mbox_t, unsigned int, stream_t *));
extern int mbox_set_hstream __P ((mbox_t, unsigned int, stream_t));
extern int mbox_get_hsize __P ((mbox_t, unsigned int, unsigned *));
extern int mbox_get_hlines __P ((mbox_t, unsigned int, unsigned *));
extern int mbox_save_attributes __P ((mbox_t));
extern int mbox_expunge __P ((mbox_t));
extern int mbox_is_modified __P ((mbox_t));
extern int mbox_get_bstream __P ((mbox_t, unsigned int, stream_t *));
extern int mbox_set_bstream __P ((mbox_t, unsigned int, stream_t));
extern int mbox_get_bsize __P ((mbox_t, unsigned int, unsigned *));
extern int mbox_get_blines __P ((mbox_t, unsigned int, unsigned *));
extern int mbox_scan __P ((mbox_t, unsigned int, unsigned int *));
extern int mbox_messages_count __P ((mbox_t, unsigned int *));
extern int mbox_get_obervable __P ((mbox_t, observable_t *));
extern int mbox_get_size __P ((mbox_t, unsigned long *));
extern int mbox_append __P ((mbox_t, message_t));
extern int mbox_save_attributes __P ((mbox_t));
extern int mbox_mark_deleted __P ((mbox_t, unsigned int));
extern int mbox_unmark_deleted __P ((mbox_t, unsigned int));
extern int mbox_expunge __P ((mbox_t));
extern int mbox_is_modified __P ((mbox_t));
extern int mbox_set_progress_cb __P ((mbox_t, int (*) __P ((int, void *)), void *));
extern int mbox_set_newmsg_cb __P ((mbox_t, int (*) __P ((int, void *)), void *));
extern int mbox_newmsg_cb __P ((mbox_t, int));
extern int mbox_progress_cb __P ((mbox_t, int));
extern int mbox_scan __P ((mbox_t, unsigned int, unsigned int *));
extern int mbox_messages_count __P ((mbox_t, unsigned int *));
extern int mbox_append __P ((mbox_t, const char *, stream_t));
extern int mbox_append_hb __P ((mbox_t, const char *, stream_t, stream_t));
#ifdef __cplusplus
......
......@@ -46,47 +46,46 @@ extern "C" {
/* A message is considered to be a container for:
header_t, body_t, and its attribute_t. */
extern int message_add_ref __P ((message_t));
extern int message_release __P ((message_t));
extern int message_destroy __P ((message_t));
extern int message_ref __P ((message_t));
extern void message_destroy __P ((message_t *));
extern int message_is_modified __P ((message_t));
extern int message_clear_modified __P ((message_t));
extern int message_get_mailbox __P ((message_t, mailbox_t *));
extern int message_is_modified __P ((message_t));
extern int message_clear_modified __P ((message_t));
extern int message_get_mailbox __P ((message_t, mailbox_t *));
extern int message_get_envelope __P ((message_t, envelope_t *));
extern int message_get_header __P ((message_t, header_t *));
extern int message_get_body __P ((message_t, body_t *));
extern int message_get_attribute __P ((message_t, attribute_t *));
extern int message_get_envelope __P ((message_t, envelope_t *));
extern int message_get_header __P ((message_t, header_t *));
extern int message_get_body __P ((message_t, body_t *));
extern int message_get_attribute __P ((message_t, attribute_t *));
extern int message_get_stream __P ((message_t, stream_t *));
extern int message_get_stream __P ((message_t, stream_t *));
extern int message_get_property __P ((message_t, property_t *));
extern int message_get_property __P ((message_t, property_t *));
extern int message_is_multipart __P ((message_t, int *));
extern int message_is_multipart __P ((message_t, int *));
extern int message_get_size __P ((message_t, size_t *));
extern int message_get_size __P ((message_t, size_t *));
extern int message_get_lines __P ((message_t, size_t *));
extern int message_get_lines __P ((message_t, size_t *));
extern int message_get_num_parts __P ((message_t, size_t *nparts));
extern int message_get_num_parts __P ((message_t, size_t *nparts));
extern int message_get_part __P ((message_t, size_t, message_t *));
extern int message_get_part __P ((message_t, size_t, message_t *));
extern int message_get_uidl __P ((message_t, char *, size_t, size_t *));
extern int message_get_uid __P ((message_t, size_t *));
extern int message_get_uidl __P ((message_t, char *, size_t, size_t *));
extern int message_get_uid __P ((message_t, size_t *));
/* misc functions */
extern int message_create_attachment __P ((const char *content_type,
const char *encoding,
const char *filename,
extern int message_create_attachment __P ((const char *content_type,
const char *encoding,
const char *filename,
message_t *newmsg));
extern int message_save_attachment __P ((message_t msg,
const char *filename, void **data));
extern int message_encapsulate __P ((message_t msg, message_t *newmsg,
void **data));
extern int message_unencapsulate __P ((message_t msg, message_t *newmsg,
void **data));
extern int message_save_attachment __P ((message_t msg,
const char *filename, void **data));
extern int message_encapsulate __P ((message_t msg, message_t *newmsg,
void **data));
extern int message_unencapsulate __P ((message_t msg, message_t *newmsg,
void **data));
#ifdef __cplusplus
}
......
......@@ -30,7 +30,7 @@
# define MU_MONITOR_INITIALIZER PTHREAD_MUTEX_INITIALIZER
# define monitor_create(m) pthread_mutex_init (m, NULL)
# define monitor_destroy(m) pthread_mutex_destroy (&m)
# define monitor_destroy(m) pthread_mutex_destroy (m)
# define monitor_cleanup_push(routine, arg) pthread_cleanup_push (routine, arg)
# define monitor_cleanup_pop(execute) pthread_cleanup_pop (execute)
......@@ -45,7 +45,7 @@
# define MU_MONITOR_INITIALIZER 0
# define monitor_create(m) (*m = 0)
# define monitor_destroy(m) (m = 0)
# define monitor_destroy(m) (*m = 0)
# define monitor_cleanup_push(routine, arg) {
# define monitor_cleanup_pop(execute) }
......
......@@ -64,6 +64,15 @@ extern char * mu_tilde_expansion __P ((const char *ref, const char *delim, const
extern size_t util_cpystr __P ((char *dst, const char *src, size_t size));
struct passwd;
extern void mu_register_getpwnam __P((struct passwd *(*fun) __P((const char *))));
extern struct passwd * mu_getpwnam __P((const char *name));
extern int mu_virtual_domain;
extern struct passwd * getpwnam_virtual __P((const char *u));
#ifdef __cplusplus
}
#endif
......
......@@ -36,13 +36,12 @@ extern "C" {
struct _observable;
typedef struct _observable *observable_t;
extern int observable_create __P ((observable_t *));
extern int observable_release __P ((observable_t));
extern int observable_destroy __P ((observable_t));
extern int observable_create __P ((observable_t *));
extern void observable_destroy __P ((observable_t *));
extern int observable_attach __P ((observable_t, int, observer_t));
extern int observable_detach __P ((observable_t, observer_t));
extern int observable_notify_all __P ((observable_t, struct event));
extern int observable_attach __P ((observable_t, int, observer_t));
extern int observable_detach __P ((observable_t, observer_t));
extern int observable_notify_all __P ((observable_t, struct event));
#ifdef __cplusplus
}
......
......@@ -53,14 +53,12 @@ struct event
#define MU_EVT_MAILBOX_CORRUPT 0x040
#define MU_EVT_MAILER_MESSAGE_SENT 0x080
extern int observer_create __P ((observer_t *, int (*action)
__P ((void *, struct event)), void *));
extern int observer_create __P ((observer_t *, int (*action)
__P ((void *, struct event)), void *));
extern int observer_add_ref __P ((observer_t));
extern int observer_release __P ((observer_t));
extern int observer_destroy __P ((observer_t));
extern int observer_action __P ((observer_t, struct event));
extern int observer_ref __P ((observer_t));
extern void observer_destroy __P ((observer_t *));
extern int observer_action __P ((observer_t, struct event));
#ifdef __cplusplus
}
......
......@@ -36,49 +36,49 @@ extern "C" {
struct _pop3;
typedef struct _pop3* pop3_t;
extern int pop3_create __P ((pop3_t *));
extern int pop3_destroy __P ((pop3_t));
extern int pop3_create __P ((pop3_t *));
extern void pop3_destroy __P ((pop3_t *));
extern int pop3_connect __P ((pop3_t, const char *, unsigned int));
extern int pop3_disconnect __P ((pop3_t));
extern int pop3_connect __P ((pop3_t, const char *, unsigned int));
extern int pop3_disconnect __P ((pop3_t));
extern int pop3_set_carrier __P ((pop3_t, stream_t));
extern int pop3_get_carrier __P ((pop3_t, stream_t *));
extern int pop3_set_carrier __P ((pop3_t, stream_t));
extern int pop3_get_carrier __P ((pop3_t, stream_t *));
extern int pop3_set_timeout __P ((pop3_t, int));
extern int pop3_get_timeout __P ((pop3_t, int *));
extern int pop3_set_timeout __P ((pop3_t, int));
extern int pop3_get_timeout __P ((pop3_t, int *));
extern int pop3_apop __P ((pop3_t, const char *, const char *));
extern int pop3_apop __P ((pop3_t, const char *, const char *));
extern int pop3_capa __P ((pop3_t, iterator_t *));
extern int pop3_capa_current __P ((iterator_t, char **));
extern int pop3_capa __P ((pop3_t, iterator_t *));
extern int pop3_capa_current __P ((iterator_t, char **));
extern int pop3_dele __P ((pop3_t, unsigned int));
extern int pop3_dele __P ((pop3_t, unsigned int));
extern int pop3_list __P ((pop3_t, unsigned int, size_t *));
extern int pop3_list_all __P ((pop3_t, iterator_t *));
extern int pop3_list_current __P ((iterator_t, unsigned int *, size_t *));
extern int pop3_list __P ((pop3_t, unsigned int, size_t *));
extern int pop3_list_all __P ((pop3_t, iterator_t *));
extern int pop3_list_current __P ((iterator_t, unsigned int *, size_t *));
extern int pop3_noop __P ((pop3_t));
extern int pop3_pass __P ((pop3_t, const char *));
extern int pop3_quit __P ((pop3_t));
extern int pop3_retr __P ((pop3_t, unsigned int, stream_t *));
extern int pop3_rset __P ((pop3_t));
extern int pop3_stat __P ((pop3_t, unsigned int *, size_t *));
extern int pop3_top __P ((pop3_t, unsigned int,
extern int pop3_noop __P ((pop3_t));
extern int pop3_pass __P ((pop3_t, const char *));
extern int pop3_quit __P ((pop3_t));
extern int pop3_retr __P ((pop3_t, unsigned int, stream_t *));
extern int pop3_rset __P ((pop3_t));
extern int pop3_stat __P ((pop3_t, unsigned int *, size_t *));
extern int pop3_top __P ((pop3_t, unsigned int,
unsigned int, stream_t *));
extern int pop3_uidl __P ((pop3_t, unsigned int, char **));
extern int pop3_uidl_all __P ((pop3_t, iterator_t *));
extern int pop3_uidl_current __P ((iterator_t, unsigned int *, char **));
extern int pop3_uidl __P ((pop3_t, unsigned int, char **));
extern int pop3_uidl_all __P ((pop3_t, iterator_t *));
extern int pop3_uidl_current __P ((iterator_t, unsigned int *, char **));
extern int pop3_user __P ((pop3_t, const char *));
extern int pop3_user __P ((pop3_t, const char *));
extern int pop3_readline __P ((pop3_t, char *, size_t, size_t *));
extern int pop3_response __P ((pop3_t, char *, size_t, size_t *));
extern int pop3_writeline __P ((pop3_t, const char *, ...));
extern int pop3_sendline __P ((pop3_t, const char *));
extern int pop3_send __P ((pop3_t));
extern int pop3_readline __P ((pop3_t, char *, size_t, size_t *));
extern int pop3_response __P ((pop3_t, char *, size_t, size_t *));
extern int pop3_writeline __P ((pop3_t, const char *, ...));
extern int pop3_sendline __P ((pop3_t, const char *));
extern int pop3_send __P ((pop3_t));
#ifdef __cplusplus
}
......
......@@ -35,17 +35,17 @@ extern "C" {
struct _property;
typedef struct _property *property_t;
extern int property_create __P ((property_t *));
extern int property_destroy __P ((property_t));
extern int property_create __P ((property_t *));
extern void property_destroy __P ((property_t *));
extern int property_set_value __P ((property_t, const char *, const char *,
int));
extern int property_get_value __P ((property_t, const char *, char * const *));
extern int property_set_value __P ((property_t, const char *, const char *,
int));
extern int property_get_value __P ((property_t, const char *, char * const *));
/* Helper functions. */
extern int property_set __P ((property_t, const char *));
extern int property_unset __P ((property_t, const char *));
extern int property_is_set __P ((property_t, const char *));
extern int property_set __P ((property_t, const char *));
extern int property_unset __P ((property_t, const char *));
extern int property_is_set __P ((property_t, const char *));
#ifdef __cplusplus
}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _MAILUTILS_REFCOUNT_H
#define _MAILUTILS_REFCOUNT_H
#include <sys/types.h>
#ifndef __P
#ifdef __STDC__
#define __P(args) args
#else
#define __P(args) ()
#endif
#endif /*__P */
#ifdef __cplusplus
extern "C" {
#endif
/* forward declaration */
struct _refcount;
typedef struct _refcount *mu_refcount_t;
extern int mu_refcount_create __P ((mu_refcount_t *));
extern void mu_refcount_destroy __P ((mu_refcount_t *));
extern int mu_refcount_inc __P ((mu_refcount_t));
extern int mu_refcount_dec __P ((mu_refcount_t));
extern int mu_refcount_lock __P ((mu_refcount_t));
extern int mu_refcount_unlock __P ((mu_refcount_t));
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_REFCOUNT_H */
......@@ -19,6 +19,7 @@
#define _MAILUTILS_STREAM_H
#include <sys/types.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
......@@ -50,40 +51,41 @@ enum stream_state
struct _stream;
typedef struct _stream *stream_t;
extern int stream_add_ref __P ((stream_t));
extern int stream_release __P ((stream_t));
extern int stream_destroy __P ((stream_t));
extern int stream_ref __P ((stream_t));
extern void stream_destroy __P ((stream_t *));
extern int stream_open __P ((stream_t, const char *, int, int));
extern int stream_close __P ((stream_t));
extern int stream_open __P ((stream_t, const char *, int, int));
extern int stream_close __P ((stream_t));
extern int stream_read __P ((stream_t, void *, size_t, size_t *));
extern int stream_readline __P ((stream_t, char *, size_t, size_t *));
extern int stream_write __P ((stream_t, const void *, size_t, size_t*));
extern int stream_read __P ((stream_t, void *, size_t, size_t *));
extern int stream_readline __P ((stream_t, char *, size_t, size_t *));
extern int stream_write __P ((stream_t, const void *, size_t, size_t*));
extern int stream_seek __P ((stream_t, off_t, enum stream_whence));
extern int stream_tell __P ((stream_t, off_t *));
extern int stream_seek __P ((stream_t, off_t, enum stream_whence));
extern int stream_tell __P ((stream_t, off_t *));
extern int stream_get_size __P ((stream_t, off_t *));
extern int stream_truncate __P ((stream_t, off_t));
extern int stream_flush __P ((stream_t));
extern int stream_get_size __P ((stream_t, off_t *));
extern int stream_truncate __P ((stream_t, off_t));
extern int stream_flush __P ((stream_t));
extern int stream_get_fd __P ((stream_t , int *));
extern int stream_get_flags __P ((stream_t, int *));
extern int stream_get_state __P ((stream_t, enum stream_state *));
extern int stream_get_fd __P ((stream_t , int *));
extern int stream_get_flags __P ((stream_t, int *));
extern int stream_get_state __P ((stream_t, enum stream_state *));
extern int stream_is_readready __P ((stream_t, int));
extern int stream_is_writeready __P ((stream_t, int));
extern int stream_is_exceptionpending __P ((stream_t, int));
extern int stream_is_readready __P ((stream_t, int));
extern int stream_is_writeready __P ((stream_t, int));
extern int stream_is_exceptionpending __P ((stream_t, int));
extern int stream_is_open __P ((stream_t));
extern int stream_is_open __P ((stream_t));
/* Misc. */
extern int stream_file_create __P ((stream_t *));
extern int stream_mapfile_create __P ((stream_t *));
extern int stream_memory_create __P ((stream_t *));
extern int stream_tcp_create __P ((stream_t *));
extern int stream_buffer_create __P ((stream_t *, stream_t, size_t));
extern int stream_file_create __P ((stream_t *));
extern int stream_stdio_create __P ((stream_t *, FILE *));
extern int stream_mapfile_create __P ((stream_t *));
extern int stream_memory_create __P ((stream_t *));
extern int stream_tcp_create __P ((stream_t *));
extern int stream_fd_create __P ((stream_t *, int));
extern int stream_buffer_create __P ((stream_t *, stream_t, size_t));
#ifdef __cplusplus
}
......
......@@ -20,6 +20,7 @@ pkginclude_HEADERS = \
observable.h \
observer.h \
pop3.h \
refcount.h \
stream.h \
tcpstream.h \
ticket.h \
......
......@@ -23,7 +23,7 @@
#endif
#include <mailutils/attribute.h>
#include <mailutils/monitor.h>
#include <mailutils/refcount.h>
#ifdef __cplusplus
extern "C" {
......@@ -39,14 +39,13 @@ extern "C" {
struct _attribute_vtable
{
int (*add_ref) __P ((attribute_t));
int (*release) __P ((attribute_t));
int (*destroy) __P ((attribute_t));
int (*ref) __P ((attribute_t));
void (*destroy) __P ((attribute_t *));
int (*get_flags) __P ((attribute_t, int *));
int (*set_flags) __P ((attribute_t, int));
int (*unset_flags) __P ((attribute_t, int));
int (*clear_flags) __P ((attribute_t));
int (*get_flags) __P ((attribute_t, int *));
int (*set_flags) __P ((attribute_t, int));
int (*unset_flags) __P ((attribute_t, int));
int (*clear_flags) __P ((attribute_t));
};
struct _attribute
......@@ -58,9 +57,8 @@ struct _attribute
struct _da
{
struct _attribute base;
int ref;
mu_refcount_t refcount;
int flags;
monitor_t lock;
};
#ifdef __cplusplus
......
......@@ -38,13 +38,12 @@ extern "C" {
struct _authority_vtable
{
int (*add_ref) __P ((authority_t));
int (*release) __P ((authority_t));
int (*destroy) __P ((authority_t));
int (*ref) __P ((authority_t));
void (*destroy) __P ((authority_t *));
int (*set_ticket) __P ((authority_t, ticket_t));
int (*get_ticket) __P ((authority_t, ticket_t *));
int (*authenticate) __P ((authority_t));
int (*set_ticket) __P ((authority_t, ticket_t));
int (*get_ticket) __P ((authority_t, ticket_t *));
int (*authenticate) __P ((authority_t));
};
struct _authority
......
......@@ -19,7 +19,7 @@
#define MAILUTILS_SYS_BSTREAM_H
#include <mailutils/sys/stream.h>
#include <mailutils/monitor.h>
#include <mailutils/refcount.h>
/* Read buffer */
struct _rbuffer
......@@ -33,10 +33,9 @@ struct _rbuffer
struct _bs
{
struct _stream base;
int ref;
mu_refcount_t refcount;
stream_t stream;
struct _rbuffer rbuffer;
monitor_t lock;
};
#endif /* _MAILUTILS_SYS_BSTREAM_H */
......
......@@ -38,12 +38,14 @@ extern "C" {
struct _envelope_vtable
{
int (*add_ref) __P ((envelope_t));
int (*release) __P ((envelope_t));
int (*destroy) __P ((envelope_t));
int (*sender) __P ((envelope_t, address_t *));
int (*recipient) __P ((envelope_t, address_t *));
int (*date) __P ((envelope_t, struct tm *, struct mu_timezone *));
int (*ref) __P ((envelope_t));
void (*destroy) __P ((envelope_t *));
int (*get_sender) __P ((envelope_t, address_t *));
int (*set_sender) __P ((envelope_t, address_t));
int (*get_recipient) __P ((envelope_t, address_t *));
int (*set_recipient) __P ((envelope_t, address_t));
int (*get_date) __P ((envelope_t, struct tm *, struct mu_timezone *));
int (*set_date) __P ((envelope_t, struct tm *, struct mu_timezone *));
};
struct _envelope
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef MAILUTILS_SYS_FDSTREAM_H
#define MAILUTILS_SYS_FDSTREAM_H
#include <mailutils/refcount.h>
#include <mailutils/sys/stream.h>
struct _fds
{
struct _stream base;
mu_refcount_t refcount;
int fd;
int state;
int flags;
};
#endif /* _MAILUTILS_SYS_FDSTREAM_H */
......@@ -35,35 +35,34 @@ extern "C" {
struct _folder_vtable
{
int (*add_ref) __P ((folder_t));
int (*release) __P ((folder_t));
int (*destroy) __P ((folder_t));
int (*ref) __P ((folder_t));
void (*destroy) __P ((folder_t *));
int (*open) __P ((folder_t, int flag));
int (*close) __P ((folder_t));
int (*open) __P ((folder_t, int flag));
int (*close) __P ((folder_t));
int (*delete) __P ((folder_t, const char *));
int (*rename) __P ((folder_t, const char *, const char *));
int (*subscribe) __P ((folder_t, const char *));
int (*unsubscribe) __P ((folder_t, const char *));
int (*list) __P ((folder_t, const char *, const char *, iterator_t *));
int (*lsub) __P ((folder_t, const char *, const char *, iterator_t *));
int (*delete) __P ((folder_t, const char *));
int (*rename) __P ((folder_t, const char *, const char *));
int (*subscribe) __P ((folder_t, const char *));
int (*unsubscribe) __P ((folder_t, const char *));
int (*list) __P ((folder_t, const char *, const char *, iterator_t *));
int (*lsub) __P ((folder_t, const char *, const char *, iterator_t *));
/* Stream settings. */
int (*get_stream) __P ((folder_t, stream_t *));
int (*set_stream) __P ((folder_t, stream_t));
int (*get_stream) __P ((folder_t, stream_t *));
int (*set_stream) __P ((folder_t, stream_t));
/* Notifications. */
int (*get_observable) __P ((folder_t, observable_t *));
int (*get_debug) __P ((folder_t, mu_debug_t *));
int (*set_debug) __P ((folder_t, mu_debug_t));
int (*get_observable) __P ((folder_t, observable_t *));
int (*get_debug) __P ((folder_t, mu_debug_t *));
int (*set_debug) __P ((folder_t, mu_debug_t));
/* Authentication. */
int (*get_authority) __P ((folder_t, authority_t *));
int (*set_authority) __P ((folder_t, authority_t));
int (*get_authority) __P ((folder_t, authority_t *));
int (*set_authority) __P ((folder_t, authority_t));
/* URL. */
int (*get_url) __P ((folder_t, url_t *));
int (*get_url) __P ((folder_t, url_t *));
};
......
......@@ -19,15 +19,14 @@
#define MAILUTILS_SYS_FSTREAM_H
#include <mailutils/sys/stream.h>
#include <mailutils/monitor.h>
#include <mailutils/refcount.h>
struct _fs
{
struct _stream base;
int ref;
mu_refcount_t refcount;
int flags;
FILE *file;
monitor_t lock;
};
#endif /* _MAILUTILS_SYS_FSTREAM_H */
......
......@@ -34,24 +34,23 @@ extern "C" {
struct _header_vtable
{
int (*add_ref) __P ((header_t));
int (*release) __P ((header_t));
int (*destroy) __P ((header_t));
int (*ref) __P ((header_t));
void (*destroy) __P ((header_t *));
int (*is_modified) __P ((header_t));
int (*clear_modified) __P ((header_t));
int (*is_modified) __P ((header_t));
int (*clear_modified) __P ((header_t));
int (*set_value) __P ((header_t, const char *, const char *, int));
int (*get_value) __P ((header_t, const char *, char *, size_t, size_t *));
int (*set_value) __P ((header_t, const char *, const char *, int));
int (*get_value) __P ((header_t, const char *, char *, size_t, size_t *));
int (*get_field_count) __P ((header_t, size_t *));
int (*get_field_value) __P ((header_t, size_t, char *, size_t, size_t *));
int (*get_field_name) __P ((header_t, size_t, char *, size_t, size_t *));
int (*get_field_count) __P ((header_t, size_t *));
int (*get_field_value) __P ((header_t, size_t, char *, size_t, size_t *));
int (*get_field_name) __P ((header_t, size_t, char *, size_t, size_t *));
int (*get_stream) __P ((header_t, stream_t *));
int (*get_stream) __P ((header_t, stream_t *));
int (*get_size) __P ((header_t, size_t *));
int (*get_lines) __P ((header_t, size_t *));
int (*get_size) __P ((header_t, size_t *));
int (*get_lines) __P ((header_t, size_t *));
};
struct _header
......
......@@ -27,14 +27,13 @@ extern "C" {
struct _iterator_vtable
{
/* Base */
int (*add_ref) __P ((iterator_t));
int (*release) __P ((iterator_t));
int (*destroy) __P ((iterator_t));
int (*first) __P ((iterator_t));
int (*next) __P ((iterator_t));
int (*current) __P ((iterator_t, void *));
int (*is_done) __P ((iterator_t));
int (*ref) __P ((iterator_t));
void (*destroy) __P ((iterator_t *));
int (*first) __P ((iterator_t));
int (*next) __P ((iterator_t));
int (*current) __P ((iterator_t, void *));
int (*is_done) __P ((iterator_t));
};
struct _iterator
......
......@@ -25,7 +25,7 @@
#include <sys/types.h>
#include <mailutils/list.h>
#include <mailutils/monitor.h>
#include <mailutils/refcount.h>
#include <mailutils/sys/iterator.h>
#ifndef __P
......@@ -52,16 +52,15 @@ struct _list
struct mu_list_data head;
size_t count;
size_t index;
monitor_t lock;
mu_refcount_t refcount;
};
struct l_iterator
{
struct _iterator base;
unsigned int ref;
mu_list_t list;
struct mu_list_data *current;
monitor_t lock;
mu_refcount_t refcount;
};
......
......@@ -38,13 +38,12 @@ extern "C" {
struct _locker_vtable
{
int (*add_ref) __P ((locker_t));
int (*release) __P ((locker_t));
int (*destroy) __P ((locker_t));
int (*ref) __P ((locker_t));
void (*destroy) __P ((locker_t *));
int (*lock) __P ((locker_t));
int (*touchlock) __P ((locker_t));
int (*unlock) __P ((locker_t));
int (*lock) __P ((locker_t));
int (*touchlock) __P ((locker_t));
int (*unlock) __P ((locker_t));
};
struct _locker
......
......@@ -35,49 +35,48 @@ extern "C" {
struct _mailbox_vtable
{
/* Constructor/destructor and possible types. */
int (*add_ref) __P ((mailbox_t));
int (*release) __P ((mailbox_t));
int (*destroy) __P ((mailbox_t));
int (*get_folder) __P ((mailbox_t, folder_t *));
int (*ref) __P ((mailbox_t));
void (*destroy) __P ((mailbox_t *));
int (*get_folder) __P ((mailbox_t, folder_t *));
int (*open) __P ((mailbox_t, int flag));
int (*close) __P ((mailbox_t));
int (*uidvalidity) __P ((mailbox_t, unsigned long *));
int (*uidnext) __P ((mailbox_t, size_t *));
int (*open) __P ((mailbox_t, int flag));
int (*close) __P ((mailbox_t));
int (*uidvalidity) __P ((mailbox_t, unsigned long *));
int (*uidnext) __P ((mailbox_t, size_t *));
/* Messages. */
int (*get_message) __P ((mailbox_t, size_t msgno, message_t *));
int (*append_message) __P ((mailbox_t, message_t));
int (*messages_count) __P ((mailbox_t, size_t *));
int (*messages_recent) __P ((mailbox_t, size_t *));
int (*messages_unseen) __P ((mailbox_t, size_t *));
int (*expunge) __P ((mailbox_t));
int (*save_attributes) __P ((mailbox_t));
int (*get_message) __P ((mailbox_t, size_t msgno, message_t *));
int (*append_message) __P ((mailbox_t, message_t));
int (*messages_count) __P ((mailbox_t, size_t *));
int (*messages_recent) __P ((mailbox_t, size_t *));
int (*messages_unseen) __P ((mailbox_t, size_t *));
int (*expunge) __P ((mailbox_t));
int (*save_attributes) __P ((mailbox_t));
/* Update and scanning. */
int (*get_size) __P ((mailbox_t, off_t *size));
int (*is_updated) __P ((mailbox_t));
int (*scan) __P ((mailbox_t, size_t no, size_t *count));
int (*get_size) __P ((mailbox_t, off_t *size));
int (*is_updated) __P ((mailbox_t));
int (*scan) __P ((mailbox_t, size_t no, size_t *count));
/* Mailbox Stream. */
int (*get_stream) __P ((mailbox_t, stream_t *));
int (*get_stream) __P ((mailbox_t, stream_t *));
/* Authentication. */
int (*get_authority) __P ((mailbox_t, authority_t *));
int (*set_authority) __P ((mailbox_t, authority_t));
int (*get_authority) __P ((mailbox_t, authority_t *));
int (*set_authority) __P ((mailbox_t, authority_t));
/* Property. */
int (*get_property) __P ((mailbox_t, property_t *));
int (*get_property) __P ((mailbox_t, property_t *));
/* URL. */
int (*get_url) __P ((mailbox_t, url_t *));
int (*get_url) __P ((mailbox_t, url_t *));
/* For any debuging */
int (*get_debug) __P ((mailbox_t, mu_debug_t *));
int (*set_debug) __P ((mailbox_t, mu_debug_t));
int (*get_debug) __P ((mailbox_t, mu_debug_t *));
int (*set_debug) __P ((mailbox_t, mu_debug_t));
/* Events. */
int (*get_observable) __P ((mailbox_t, observable_t *));
int (*get_observable) __P ((mailbox_t, observable_t *));
};
struct _mailbox
......
......@@ -19,7 +19,6 @@
#define _MAILUTILS_SYS_MBOX_H
#include <time.h>
#include <mailutils/monitor.h>
#include <mailutils/locker.h>
#include <mailutils/mbox.h>
......@@ -29,68 +28,33 @@ extern "C" {
typedef struct _mbox_message* mbox_message_t;
/* Below are the headers field-names that we are caching for speed, it is
more or less the list of headers in ENVELOPE command from IMAP. */
#define HDRSIZE 15
const char *fhdr_table[] =
{
#define H_BCC 0
"Bcc",
#define H_CC 1
"Cc",
#define H_CONTENT_LANGUAGE 2
"Content-Language",
#define H_CONTENT_TRANSFER_ENCODING 3
"Content-Transfer-Encoding",
#define H_CONTENT_TYPE 4
"Content-Type",
#define H_DATE 5
"Date",
#define H_FROM 6
"From",
#define H_IN_REPLY_TO 7
"In-Reply-To",
#define H_MESSAGE_ID 8
"Message-ID",
#define H_REFERENCE 9
"Reply-To",
#define H_REPLY_TO 10
"Reply-To",
#define H_SENDER 11
"Sender",
#define H_SUBJECT 12
"Subject",
#define H_TO 13
"To",
#define H_X_UIDL 14
"X-UIDL"
};
/* Keep the file positions of where the headers and bodies start and end.
attr_flags is the "Status:" message. */
attribute is the "Status:" message. */
struct _mbox_message
{
/* Offset of the messages in the mailbox. */
off_t header_from;
off_t header_from_end;
off_t body;
off_t body_end;
off_t from_;
/* Fast header retrieve, we save here the most common headers. This will
speed the header search. The entire headers are copied, when modified,
by the header_t object, we do not have to worry about updating them. */
char *fhdr[HDRSIZE];
size_t uid; /* IMAP uid. */
int attr_flags; /* The attr_flags contains the "Status:" attribute */
size_t header_lines;
size_t body_lines;
char **fhdr;
message_t message; /* A message attach to it. */
mbox_t mud; /* Back pointer. */
struct
{
stream_t stream;
unsigned int lines;
unsigned int size;
off_t start;
off_t end;
} header, body;
/* UID i.e. see IMAP */
unsigned long uid;
attribute_t attribute; /* The attr_flags contains the "Status:" attribute */
mbox_t mbox; /* Back pointer. */
};
/* The umessages is an array of pointers that contains umessages_count of
......@@ -101,10 +65,12 @@ struct _mbox_message
struct _mbox
{
mbox_message_t *umessages; /* Array. */
size_t umessages_count; /* How big is the umessages[]. */
size_t messages_count; /* How many valid entry in umessages[]. */
unsigned int umessages_count; /* How big is the umessages[]. */
unsigned int messages_count; /* Number of messages. */
stream_t carrier; /* File stream. */
stream_t stream;
off_t size; /* Size of the mailbox. */
time_t mtime; /* Modified time. */
unsigned long uidvalidity;
......@@ -115,32 +81,18 @@ struct _mbox
enum mbox_state
{
MBOX_NO_STATE = 0,
MBOX_STATE_APPEND_SENDER, MBOX_STATE_APPEND_DATE, MBOX_STATE_APPEND_HEADER,
MBOX_STATE_APPEND_ATTRIBUTE, MBOX_STATE_APPEND_UID, MBOX_STATE_APPEND_BODY,
MBOX_STATE_APPEND_MESSAGE
MBOX_STATE_APPEND_HEADER,
MBOX_STATE_APPEND_BODY
} state ;
char *sender;
char *to;
char *date;
off_t off;
monitor_t lock;
mu_debug_t debug;
locker_t locker;
observable_t observable;
};
/* Moro(?)ic kluge. */
#define MBOX_DEBUG0(mbox, type, format) \
if (mbox->debug) mu_debug_print (mbox->debug, type, format)
#define MBOX_DEBUG1(mbox, type, format, arg1) \
if (mbox->debug) mu_debug_print (mbox->debug, type, format, arg1)
#define MBOX_DEBUG2(mbox, type, format, arg1, arg2) \
if (mbox->debug) mu_debug_print (mbox->debug, type, format, arg1, arg2)
#define MBOX_DEBUG3(mbox, type, format, arg1, arg2, arg3) \
if (mbox->debug) mu_debug_print (mbox->debug, type, format, arg1, arg2, arg3)
#define MBOX_DEBUG4(mbox, type, format, arg1, arg2, arg3, arg4) \
if (mbox->debug) mu_debug_print (mbox->debug, type, format, arg1, arg2, arg3, arg4)
struct
{
int (*cb) __P ((int, void *));
void *arg;
} newmsg, progress, corrupt;
};
#ifdef __cplusplus
}
......
......@@ -20,18 +20,17 @@
#include <sys/types.h>
#include <mailutils/monitor.h>
#include <mailutils/refcount.h>
#include <mailutils/sys/stream.h>
struct _memory_stream
{
struct _stream base;
int ref;
mu_refcount_t refcount;
char *ptr;
size_t size;
off_t offset;
int flags;
monitor_t lock;
};
#endif /* _MAILUTILS_SYS_MEMSTREAM_H */
......
......@@ -37,35 +37,34 @@ extern "C" {
struct _message_vtable
{
int (*add_ref) __P ((message_t));
int (*release) __P ((message_t));
int (*destroy) __P ((message_t));
int (*ref) __P ((message_t));
void (*destroy) __P ((message_t *));
int (*is_modified) __P ((message_t));
int (*clear_modified) __P ((message_t));
int (*get_mailbox) __P ((message_t, mailbox_t *));
int (*is_modified) __P ((message_t));
int (*clear_modified) __P ((message_t));
int (*get_mailbox) __P ((message_t, mailbox_t *));
int (*get_envelope) __P ((message_t, envelope_t *));
int (*get_header) __P ((message_t, header_t *));
int (*get_body) __P ((message_t, body_t *));
int (*get_attribute) __P ((message_t, attribute_t *));
int (*get_envelope) __P ((message_t, envelope_t *));
int (*get_header) __P ((message_t, header_t *));
int (*get_body) __P ((message_t, body_t *));
int (*get_attribute) __P ((message_t, attribute_t *));
int (*get_stream) __P ((message_t, stream_t *));
int (*get_stream) __P ((message_t, stream_t *));
int (*get_property) __P ((message_t, property_t *));
int (*get_property) __P ((message_t, property_t *));
int (*is_multipart) __P ((message_t, int *));
int (*is_multipart) __P ((message_t, int *));
int (*get_size) __P ((message_t, size_t *));
int (*get_size) __P ((message_t, size_t *));
int (*get_lines) __P ((message_t, size_t *));
int (*get_lines) __P ((message_t, size_t *));
int (*get_num_parts) __P ((message_t, size_t *nparts));
int (*get_num_parts) __P ((message_t, size_t *nparts));
int (*get_part) __P ((message_t, size_t, message_t *));
int (*get_part) __P ((message_t, size_t, message_t *));
int (*get_uidl) __P ((message_t, char *, size_t, size_t *));
int (*get_uid) __P ((message_t, size_t *));
int (*get_uidl) __P ((message_t, char *, size_t, size_t *));
int (*get_uid) __P ((message_t, size_t *));
};
struct _message
......
......@@ -19,19 +19,18 @@
#define MAILUTILS_SYS_MSTREAM_H
#include <mailutils/sys/stream.h>
#include <mailutils/monitor.h>
#include <mailutils/refcount.h>
struct _ms
{
struct _stream base;
int ref;
mu_refcount_t refcount;
int fd;
int flags;
int mflags;
char *ptr;
size_t size;
off_t offset;
monitor_t lock;
};
#endif /* _MAILUTILS_SYS_MSTREAM_H */
......
......@@ -22,7 +22,6 @@
# include <dmalloc.h>
#endif
#include <mailutils/monitor.h>
#include <mailutils/list.h>
#include <mailutils/observable.h>
......
......@@ -22,7 +22,7 @@
# include <dmalloc.h>
#endif
#include <mailutils/monitor.h>
#include <mailutils/refcount.h>
#include <mailutils/observer.h>
#include <mailutils/list.h>
......@@ -40,11 +40,10 @@ extern "C" {
struct _observer_vtable
{
int (*add_ref) __P ((observer_t));
int (*release) __P ((observer_t));
int (*destroy) __P ((observer_t));
int (*ref) __P ((observer_t));
void (*destroy) __P ((observer_t *));
int (*action) __P ((observer_t, struct event));
int (*action) __P ((observer_t, struct event));
};
struct _observer
......@@ -60,10 +59,9 @@ struct _observable
struct _dobserver
{
struct _observer base;
int ref;
mu_refcount_t refcount;
void *arg;
int (*action) __P ((void *, struct event));
monitor_t lock;
};
#ifdef __cplusplus
......
......@@ -24,7 +24,7 @@
#include <mailutils/sys/stream.h>
#include <mailutils/sys/iterator.h>
#include <mailutils/error.h>
#include <mailutils/monitor.h>
#include <mailutils/refcount.h>
#ifdef DMALLOC
# include <dmalloc.h>
......@@ -59,19 +59,17 @@ struct p_iterator
{
struct _iterator base;
pop3_t pop3;
unsigned int ref;
mu_refcount_t refcount;
int done;
char *item;
monitor_t lock;
};
struct p_stream
{
struct _stream base;
pop3_t pop3;
unsigned ref;
mu_refcount_t refcount;
int done;
monitor_t lock;
};
struct work_buf
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _MAILUTILS_SYS_REFCOUNT_H
#define _MAILUTILS_SYS_REFCOUNT_H
#ifdef DMALLOC
#include <dmalloc.h>
#endif
#include <mailutils/refcount.h>
#include <mailutils/monitor.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*__P */
struct _refcount
{
unsigned int ref;
monitor_t lock;
};
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_SYS_REFCOUNT_H */
......@@ -26,33 +26,32 @@ extern "C" {
struct _stream_vtable
{
int (*add_ref) __P ((stream_t));
int (*release) __P ((stream_t));
int (*destroy) __P ((stream_t));
int (*ref) __P ((stream_t));
void (*destroy) __P ((stream_t *));
int (*open) __P ((stream_t, const char *, int, int));
int (*close) __P ((stream_t));
int (*open) __P ((stream_t, const char *, int, int));
int (*close) __P ((stream_t));
int (*read) __P ((stream_t, void *, size_t, size_t *));
int (*readline) __P ((stream_t, char *, size_t, size_t *));
int (*write) __P ((stream_t, const void *, size_t, size_t *));
int (*read) __P ((stream_t, void *, size_t, size_t *));
int (*readline) __P ((stream_t, char *, size_t, size_t *));
int (*write) __P ((stream_t, const void *, size_t, size_t *));
int (*seek) __P ((stream_t, off_t, enum stream_whence));
int (*tell) __P ((stream_t, off_t *));
int (*seek) __P ((stream_t, off_t, enum stream_whence));
int (*tell) __P ((stream_t, off_t *));
int (*get_size) __P ((stream_t, off_t *));
int (*truncate) __P ((stream_t, off_t));
int (*flush) __P ((stream_t));
int (*get_size) __P ((stream_t, off_t *));
int (*truncate) __P ((stream_t, off_t));
int (*flush) __P ((stream_t));
int (*get_fd) __P ((stream_t , int *));
int (*get_flags) __P ((stream_t, int *));
int (*get_state) __P ((stream_t, enum stream_state *));
int (*get_fd) __P ((stream_t , int *));
int (*get_flags) __P ((stream_t, int *));
int (*get_state) __P ((stream_t, enum stream_state *));
int (*is_readready) __P ((stream_t, int));
int (*is_writeready) __P ((stream_t, int));
int (*is_exceptionpending) __P ((stream_t, int));
int (*is_readready) __P ((stream_t, int));
int (*is_writeready) __P ((stream_t, int));
int (*is_exceptionpending) __P ((stream_t, int));
int (*is_open) __P ((stream_t));
int (*is_open) __P ((stream_t));
};
struct _stream
......
......@@ -18,7 +18,7 @@
#ifndef MAILUTILS_SYS_TCP_H
#define MAILUTILS_SYS_TCP_H
#include <mailutils/monitor.h>
#include <mailutils/refcount.h>
#include <mailutils/sys/stream.h>
enum _tcp_state
......@@ -33,14 +33,13 @@ enum _tcp_state
struct _tcp_instance
{
struct _stream base;
int ref;
mu_refcount_t refcount;
int fd;
char *host;
int port;
int state;
int flags;
unsigned long address;
monitor_t lock;
};
#endif /* _MAILUTILS_SYS_TCP_H */
......
......@@ -38,11 +38,10 @@ extern "C" {
struct _ticket_vtable
{
int (*add_ref) __P ((ticket_t));
int (*release) __P ((ticket_t));
int (*destroy) __P ((ticket_t));
int (*ref) __P ((ticket_t));
void (*destroy) __P ((ticket_t *));
int (*pop) __P ((ticket_t, const char *, char **));
int (*pop) __P ((ticket_t, const char *, char **));
};
struct _ticket
......
......@@ -36,13 +36,12 @@ extern "C" {
struct _ticket;
typedef struct _ticket *ticket_t;
extern int ticket_add_ref __P ((ticket_t));
extern int ticket_release __P ((ticket_t));
extern int ticket_destroy __P ((ticket_t));
extern int ticket_ref __P ((ticket_t));
extern void ticket_destroy __P ((ticket_t *));
extern int ticket_pop __P ((ticket_t, const char *, char **));
extern int ticket_pop __P ((ticket_t, const char *, char **));
extern int ticket_prompt_create __P ((ticket_t *));
extern int ticket_prompt_create __P ((ticket_t *));
#ifdef __cplusplus
}
......
......@@ -36,33 +36,33 @@ extern "C" {
struct _url;
typedef struct _url * url_t;
extern int url_destroy __P ((url_t));
extern int url_parse __P ((url_t));
extern void url_destroy __P ((url_t *));
extern int url_parse __P ((url_t));
extern int url_get_scheme __P ((const url_t, char *, size_t, size_t *));
extern int url_get_user __P ((const url_t, char *, size_t, size_t *));
extern int url_get_passwd __P ((const url_t, char *, size_t, size_t *));
extern int url_get_auth __P ((const url_t, char *, size_t, size_t *));
extern int url_get_host __P ((const url_t, char *, size_t, size_t *));
extern int url_get_port __P ((const url_t, long *));
extern int url_get_path __P ((const url_t, char *, size_t, size_t *));
extern int url_get_query __P ((const url_t, char *, size_t, size_t *));
extern int url_get_scheme __P ((const url_t, char *, size_t, size_t *));
extern int url_get_user __P ((const url_t, char *, size_t, size_t *));
extern int url_get_passwd __P ((const url_t, char *, size_t, size_t *));
extern int url_get_auth __P ((const url_t, char *, size_t, size_t *));
extern int url_get_host __P ((const url_t, char *, size_t, size_t *));
extern int url_get_port __P ((const url_t, long *));
extern int url_get_path __P ((const url_t, char *, size_t, size_t *));
extern int url_get_query __P ((const url_t, char *, size_t, size_t *));
extern const char* url_to_string __P ((const url_t));
extern int url_is_same_scheme __P ((url_t, url_t));
extern int url_is_same_user __P ((url_t, url_t));
extern int url_is_same_path __P ((url_t, url_t));
extern int url_is_same_host __P ((url_t, url_t));
extern int url_is_same_port __P ((url_t, url_t));
extern int url_is_same_scheme __P ((url_t, url_t));
extern int url_is_same_user __P ((url_t, url_t));
extern int url_is_same_path __P ((url_t, url_t));
extern int url_is_same_host __P ((url_t, url_t));
extern int url_is_same_port __P ((url_t, url_t));
extern char* url_decode __P ((const char *s));
extern int url_imap_create __P ((url_t *, const char *));
extern int url_pop_create __P ((url_t *, const char *));
extern int url_file_create __P ((url_t *, const char *));
extern int url_path_create __P ((url_t *, const char *));
extern int url_mbox_create __P ((url_t *, const char *));
extern int url_smtp_create __P ((url_t *, const char *));
extern int url_imap_create __P ((url_t *, const char *));
extern int url_pop_create __P ((url_t *, const char *));
extern int url_file_create __P ((url_t *, const char *));
extern int url_path_create __P ((url_t *, const char *));
extern int url_mbox_create __P ((url_t *, const char *));
extern int url_smtp_create __P ((url_t *, const char *));
#ifdef __cplusplus
}
......
......@@ -24,26 +24,20 @@
#include <mailutils/sys/iterator.h>
#include <mailutils/error.h>
int
(iterator_release) (iterator_t iterator)
void
iterator_destroy (iterator_t *piterator)
{
if (iterator == NULL || iterator->vtable == NULL
|| iterator->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return iterator->vtable->release (iterator);
}
int
(iterator_destroy) (iterator_t iterator)
{
if (iterator == NULL || iterator->vtable == NULL
|| iterator->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return iterator->vtable->destroy (iterator);
if (piterator && *piterator)
{
iterator_t iterator = *piterator;
if (iterator->vtable && iterator->vtable->destroy)
iterator->vtable->destroy (piterator);
*piterator = NULL;
}
}
int
(iterator_first) (iterator_t iterator)
iterator_first (iterator_t iterator)
{
if (iterator == NULL || iterator->vtable == NULL
|| iterator->vtable->first == NULL)
......@@ -52,7 +46,7 @@ int
}
int
(iterator_next) (iterator_t iterator)
iterator_next (iterator_t iterator)
{
if (iterator == NULL || iterator->vtable == NULL
|| iterator->vtable->next == NULL)
......@@ -61,7 +55,7 @@ int
}
int
(iterator_current) (iterator_t iterator, void *pitem)
iterator_current (iterator_t iterator, void *pitem)
{
if (iterator == NULL || iterator->vtable == NULL
|| iterator->vtable->current == NULL)
......@@ -70,7 +64,7 @@ int
}
int
(iterator_is_done) (iterator_t iterator)
iterator_is_done (iterator_t iterator)
{
if (iterator == NULL || iterator->vtable == NULL
|| iterator->vtable->is_done == NULL)
......
......@@ -38,8 +38,8 @@ mu_list_create (mu_list_t *plist)
list = calloc (sizeof (*list), 1);
if (list == NULL)
return ENOMEM;
status = monitor_create (&(list->lock));
if (status != 0)
status = mu_refcount_create (&(list->refcount));
if (list->refcount == NULL)
{
free (list);
return status;
......@@ -52,26 +52,36 @@ mu_list_create (mu_list_t *plist)
}
int
mu_list_destroy (mu_list_t list)
mu_list_ref (mu_list_t list)
{
if (list)
return mu_refcount_inc (list->refcount);
return 0;
}
void
mu_list_destroy (mu_list_t *plist)
{
if (plist && *plist)
{
struct mu_list_data *current;
struct mu_list_data *previous;
monitor_lock (list->lock);
for (current = list->head.next; current != &(list->head);)
mu_list_t list = *plist;
if (mu_refcount_dec (list->refcount) == 0)
{
previous = current;
current = current->next;
free (previous);
struct mu_list_data *current;
struct mu_list_data *previous;
mu_refcount_lock (list->refcount);
for (current = list->head.next; current != &(list->head);)
{
previous = current;
current = current->next;
free (previous);
}
mu_refcount_unlock (list->refcount);
mu_refcount_destroy (&list->refcount);
free (list);
}
monitor_unlock (list->lock);
monitor_destroy (list->lock);
free (list);
*plist = NULL;
}
return 0;
}
int
mu_list_append (mu_list_t list, void *item)
{
......@@ -84,13 +94,13 @@ mu_list_append (mu_list_t list, void *item)
if (ldata == NULL)
return ENOMEM;
ldata->item = item;
monitor_lock (list->lock);
mu_refcount_lock (list->refcount);
ldata->next = &(list->head);
ldata->prev = list->head.prev;
last->next = ldata;
list->head.prev = ldata;
list->count++;
monitor_unlock (list->lock);
mu_refcount_unlock (list->refcount);
return 0;
}
......@@ -106,13 +116,13 @@ mu_list_prepend (mu_list_t list, void *item)
if (ldata == NULL)
return ENOMEM;
ldata->item = item;
monitor_lock (list->lock);
mu_refcount_lock (list->refcount);
ldata->prev = &(list->head);
ldata->next = list->head.next;
first->prev = ldata;
list->head.next = ldata;
list->count++;
monitor_unlock (list->lock);
mu_refcount_unlock (list->refcount);
return 0;
}
......@@ -129,7 +139,9 @@ mu_list_count (mu_list_t list, size_t *pcount)
{
if (list == NULL || pcount == NULL)
return EINVAL;
mu_refcount_lock (list->refcount);
*pcount = list->count;
mu_refcount_unlock (list->refcount);
return 0;
}
......@@ -140,7 +152,7 @@ mu_list_remove (mu_list_t list, void *item)
int status = ENOENT;
if (list == NULL)
return EINVAL;
monitor_lock (list->lock);
mu_refcount_lock (list->refcount);
for (previous = &(list->head), current = list->head.next;
current != &(list->head); previous = current, current = current->next)
{
......@@ -154,7 +166,7 @@ mu_list_remove (mu_list_t list, void *item)
break;
}
}
monitor_unlock (list->lock);
mu_refcount_unlock (list->refcount);
return ENOENT;
}
......@@ -166,7 +178,7 @@ mu_list_get (mu_list_t list, size_t index, void **pitem)
int status = ENOENT;
if (list == NULL || pitem == NULL)
return EINVAL;
monitor_lock (list->lock);
mu_refcount_lock (list->refcount);
for (current = list->head.next, count = 0; current != &(list->head);
current = current->next, count++)
{
......@@ -177,23 +189,21 @@ mu_list_get (mu_list_t list, size_t index, void **pitem)
break;
}
}
monitor_unlock (list->lock);
mu_refcount_unlock (list->refcount);
return status;
}
static int l_add_ref __P ((iterator_t));
static int l_release __P ((iterator_t));
static int l_destroy __P ((iterator_t));
static int l_first __P ((iterator_t));
static int l_next __P ((iterator_t));
static int l_current __P ((iterator_t, void *));
static int l_is_done __P ((iterator_t));
static int l_ref __P ((iterator_t));
static void l_destroy __P ((iterator_t *));
static int l_first __P ((iterator_t));
static int l_next __P ((iterator_t));
static int l_current __P ((iterator_t, void *));
static int l_is_done __P ((iterator_t));
static struct _iterator_vtable l_i_vtable =
{
/* Base. */
l_add_ref,
l_release,
l_ref,
l_destroy,
l_first,
......@@ -214,56 +224,39 @@ mu_list_get_iterator (mu_list_t list, iterator_t *piterator)
if (l_iterator == NULL)
return MU_ERROR_NO_MEMORY;
l_iterator->base.vtable = &l_i_vtable;
l_iterator->ref = 1;
mu_refcount_create (&l_iterator->refcount);
if (l_iterator->refcount == NULL)
{
free (l_iterator);
return MU_ERROR_NO_MEMORY;
}
/* Incremente the reference count of the list. */
l_iterator->list = list;
mu_list_ref (list);
l_iterator->current = NULL;
monitor_create (&(l_iterator->lock));
l_iterator->base.vtable = &l_i_vtable;
*piterator = &l_iterator->base;
return 0;
}
static int
l_add_ref (iterator_t iterator)
l_ref (iterator_t iterator)
{
int status = 0;
struct l_iterator *l_iterator = (struct l_iterator *)iterator;
if (l_iterator)
{
monitor_lock (l_iterator->lock);
status = ++l_iterator->ref;
monitor_unlock (l_iterator->lock);
}
return status;
return mu_refcount_inc (l_iterator->refcount);
}
static int
l_release (iterator_t iterator)
static void
l_destroy (iterator_t *piterator)
{
int status = 0;
struct l_iterator *l_iterator = (struct l_iterator *)iterator;
if (l_iterator)
struct l_iterator *l_iterator = (struct l_iterator *)*piterator;
if (mu_refcount_dec (l_iterator->refcount) == 0)
{
monitor_lock (l_iterator->lock);
status = --l_iterator->ref;
if (status <= 0)
{
monitor_unlock (l_iterator->lock);
l_destroy (iterator);
return 0;
}
monitor_unlock (l_iterator->lock);
/* The reference was bumped when creating the iterator. */
mu_list_destroy (&l_iterator->list);
mu_refcount_destroy (&l_iterator->refcount);
free (l_iterator);
}
return status;
}
static int
l_destroy (iterator_t iterator)
{
struct l_iterator *l_iterator = (struct l_iterator *)iterator;
monitor_destroy (l_iterator->lock);
free (l_iterator);
return 0;
}
static int
......@@ -273,9 +266,9 @@ l_first (iterator_t iterator)
mu_list_t list = l_iterator->list;
if (list)
{
monitor_lock (list->lock);
mu_refcount_lock (list->refcount);
l_iterator->current = l_iterator->list->head.next;
monitor_unlock (list->lock);
mu_refcount_unlock (list->refcount);
}
return 0;
}
......@@ -289,9 +282,9 @@ l_next (iterator_t iterator)
{
if (l_iterator->current)
{
monitor_lock (list->lock);
mu_refcount_lock (list->refcount);
l_iterator->current = l_iterator->current->next;
monitor_unlock (list->lock);
mu_refcount_unlock (list->refcount);
}
else
l_first (iterator);
......@@ -307,9 +300,9 @@ l_is_done (iterator_t iterator)
mu_list_t list = l_iterator->list;
if (list)
{
monitor_lock (list->lock);
mu_refcount_lock (list->refcount);
done = (l_iterator->current == &(list->head));
monitor_unlock (list->lock);
mu_refcount_unlock (list->refcount);
}
return done;
}
......@@ -321,12 +314,12 @@ l_current (iterator_t iterator, void *item)
mu_list_t list = l_iterator->list;
if (list)
{
monitor_lock (list->lock);
mu_refcount_lock (list->refcount);
if (l_iterator->current)
*((void **)item) = l_iterator->current->item;
else
*((void **)item) = NULL;
monitor_unlock (list->lock);
mu_refcount_unlock (list->refcount);
}
return 0;
}
......
......@@ -24,34 +24,28 @@
#include <mailutils/sys/locker.h>
int
(locker_add_ref) (locker_t locker)
locker_ref (locker_t locker)
{
if (locker == NULL || locker->vtable == NULL
|| locker->vtable->add_ref == NULL)
|| locker->vtable->ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return locker->vtable->add_ref (locker);
return locker->vtable->ref (locker);
}
int
(locker_release) (locker_t locker)
void
locker_destroy (locker_t *plocker)
{
if (locker == NULL || locker->vtable == NULL
|| locker->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return locker->vtable->release (locker);
}
int
(locker_destroy) (locker_t locker)
{
if (locker == NULL || locker->vtable == NULL
|| locker->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return locker->vtable->destroy (locker);
if (plocker && *plocker)
{
locker_t locker = *plocker;
if (locker->vtable && locker->vtable->destroy)
locker->vtable->destroy (plocker);
*plocker = NULL;
}
}
int
(locker_lock) (locker_t locker)
locker_lock (locker_t locker)
{
if (locker == NULL || locker->vtable == NULL
|| locker->vtable->lock == NULL)
......@@ -60,7 +54,7 @@ int
}
int
(locker_touchlock) (locker_t locker)
locker_touchlock (locker_t locker)
{
if (locker == NULL || locker->vtable == NULL
|| locker->vtable->lock == NULL)
......@@ -69,7 +63,7 @@ int
}
int
(locker_unlock) (locker_t locker)
locker_unlock (locker_t locker)
{
if (locker == NULL || locker->vtable == NULL
|| locker->vtable->lock == NULL)
......
......@@ -19,30 +19,24 @@
#include <mailutils/sys/mailbox.h>
int
mailbox_add_ref (mailbox_t mailbox)
mailbox_ref (mailbox_t mailbox)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->add_ref == NULL)
|| mailbox->vtable->ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->add_ref (mailbox);
return mailbox->vtable->ref (mailbox);
}
int
mailbox_release (mailbox_t mailbox)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->release (mailbox);
}
int
mailbox_destroy (mailbox_t mailbox)
void
mailbox_destroy (mailbox_t *pmailbox)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->destroy (mailbox);
if (pmailbox && *pmailbox)
{
mailbox_t mailbox = *pmailbox;
if (mailbox->vtable && mailbox->vtable->destroy)
mailbox->vtable->destroy (pmailbox);
*pmailbox = NULL;
}
}
int
......@@ -182,7 +176,6 @@ mailbox_scan (mailbox_t mailbox, size_t no, size_t *count)
return mailbox->vtable->scan (mailbox, no, count);
}
/* Mailbox Stream. */
int
mailbox_get_stream (mailbox_t mailbox, stream_t *stream)
......@@ -193,7 +186,6 @@ mailbox_get_stream (mailbox_t mailbox, stream_t *stream)
return mailbox->vtable->get_stream (mailbox, stream);
}
/* Authentication. */
int
mailbox_get_authority (mailbox_t mailbox, authority_t *authority)
......@@ -223,7 +215,6 @@ mailbox_get_property (mailbox_t mailbox, property_t *property)
return mailbox->vtable->get_property (mailbox, property);
}
/* URL. */
int
mailbox_get_url (mailbox_t mailbox, url_t *url)
......@@ -234,7 +225,6 @@ mailbox_get_url (mailbox_t mailbox, url_t *url)
return mailbox->vtable->get_url (mailbox, url);
}
/* For any debuging */
int
mailbox_get_debug (mailbox_t mailbox, mu_debug_t *debug)
......@@ -254,7 +244,6 @@ mailbox_set_debug (mailbox_t mailbox, mu_debug_t debug)
return mailbox->vtable->set_debug (mailbox, debug);
}
/* Events. */
int
mailbox_get_observable (mailbox_t mailbox, observable_t *observable)
......
......@@ -40,48 +40,29 @@
#endif
static int
_map_add_ref (stream_t stream)
_map_ref (stream_t stream)
{
int status;
struct _ms *ms = (struct _ms *)stream;
monitor_lock (ms->lock);
status = ++ms->ref;
monitor_unlock (ms->lock);
return status;
return mu_refcount_inc (ms->refcount);
}
static int
_map_destroy (stream_t stream)
static void
_map_destroy (stream_t *pstream)
{
struct _ms *ms = (struct _ms *)stream;
struct _ms *ms = (struct _ms *)*pstream;
if (ms->ptr != MAP_FAILED)
if (mu_refcount_dec (ms->refcount) == 0)
{
if (ms->ptr)
munmap (ms->ptr, ms->size);
if (ms->ptr != MAP_FAILED)
{
if (ms->ptr)
munmap (ms->ptr, ms->size);
}
if (ms->fd != -1)
close (ms->fd);
monitor_destroy (ms->lock);
mu_refcount_destroy (&ms->refcount);
free (ms);
}
free (ms);
return 0;
}
static int
_map_release (stream_t stream)
{
int status;
struct _ms *ms = (struct _ms *)stream;
monitor_lock (ms->lock);
status = --ms->ref;
if (status <= 0)
{
monitor_unlock (ms->lock);
_map_destroy (stream);
return 0;
}
monitor_unlock (ms->lock);
return status;
}
static int
......@@ -90,7 +71,7 @@ _map_read (stream_t stream, void *optr, size_t osize, size_t *nbytes)
struct _ms *ms = (struct _ms *)stream;
size_t n = 0;
monitor_lock (ms->lock);
mu_refcount_lock (ms->refcount);
if (ms->ptr != MAP_FAILED && ms->ptr)
{
if (ms->offset < (off_t)ms->size)
......@@ -101,7 +82,7 @@ _map_read (stream_t stream, void *optr, size_t osize, size_t *nbytes)
ms->offset += n;
}
}
monitor_unlock (ms->lock);
mu_refcount_unlock (ms->refcount);
if (nbytes)
*nbytes = n;
......@@ -114,7 +95,7 @@ _map_readline (stream_t stream, char *optr, size_t osize, size_t *nbytes)
struct _ms *ms = (struct _ms *)stream;
size_t n = 0;
monitor_lock (ms->lock);
mu_refcount_lock (ms->refcount);
if (ms->ptr != MAP_FAILED && ms->ptr)
{
if (ms->offset < (off_t)ms->size)
......@@ -130,7 +111,7 @@ _map_readline (stream_t stream, char *optr, size_t osize, size_t *nbytes)
ms->offset += n;
}
}
monitor_unlock (ms->lock);
mu_refcount_unlock (ms->refcount);
if (nbytes)
*nbytes = n;
......@@ -144,7 +125,7 @@ _map_write (stream_t stream, const void *iptr, size_t isize, size_t *nbytes)
int err = 0;
size_t n = 0;
monitor_lock (ms->lock);
mu_refcount_lock (ms->refcount);
if (ms->mflags & PROT_WRITE)
{
/* Bigger we have to remmap. */
......@@ -175,7 +156,8 @@ _map_write (stream_t stream, const void *iptr, size_t isize, size_t *nbytes)
}
else
err = MU_ERROR_IO;
monitor_unlock (ms->lock);
mu_refcount_lock (ms->refcount);
if (nbytes)
*nbytes = n;
......@@ -188,7 +170,7 @@ _map_truncate (stream_t stream, off_t len)
struct _ms *ms = (struct _ms *)stream;
int err = 0;
monitor_lock (ms->lock);
mu_refcount_lock (ms->refcount);
if (ms->ptr != MAP_FAILED)
{
/* Remap. */
......@@ -209,7 +191,7 @@ _map_truncate (stream_t stream, off_t len)
err = errno;
}
}
monitor_unlock (ms->lock);
mu_refcount_unlock (ms->refcount);
return err;
}
......@@ -220,7 +202,7 @@ _map_get_size (stream_t stream, off_t *psize)
struct stat stbuf;
int err = 0;
monitor_lock (ms->lock);
mu_refcount_lock (ms->refcount);
stbuf.st_size = 0;
if (ms->ptr != MAP_FAILED)
{
......@@ -251,7 +233,7 @@ _map_get_size (stream_t stream, off_t *psize)
}
}
}
monitor_unlock (ms->lock);
mu_refcount_unlock (ms->refcount);
if (psize)
*psize = stbuf.st_size;
return err;
......@@ -262,10 +244,10 @@ _map_flush (stream_t stream)
{
int err = 0;
struct _ms *ms = (struct _ms *)stream;
monitor_lock (ms->lock);
mu_refcount_lock (ms->refcount);
if (ms->ptr != MAP_FAILED && ms->ptr != NULL)
err = msync (ms->ptr, ms->size, MS_SYNC);
monitor_unlock (ms->lock);
mu_refcount_unlock (ms->refcount);
return 0;
}
......@@ -338,7 +320,7 @@ _map_close (stream_t stream)
{
struct _ms *ms = (struct _ms *)stream;
int err = 0;
monitor_lock (ms->lock);
mu_refcount_lock (ms->refcount);
if (ms->ptr != MAP_FAILED)
{
if (ms->ptr && munmap (ms->ptr, ms->size) != 0)
......@@ -349,7 +331,7 @@ _map_close (stream_t stream)
if (close (ms->fd) != 0)
err = errno;
ms->fd = -1;
monitor_unlock (ms->lock);
mu_refcount_unlock (ms->refcount);
return err;
}
......@@ -455,8 +437,7 @@ _map_open (stream_t stream, const char *filename, int port, int flags)
static struct _stream_vtable _map_vtable =
{
_map_add_ref,
_map_release,
_map_ref,
_map_destroy,
_map_open,
......@@ -501,13 +482,17 @@ stream_mapfile_create (stream_t *pstream)
if (ms == NULL)
return MU_ERROR_NO_MEMORY;
ms->base.vtable = &_map_vtable;
ms->ref = 1;
mu_refcount_create (&ms->refcount);
if (ms->refcount == NULL)
{
free (ms);
return MU_ERROR_NO_MEMORY;
}
ms->fd = -1;
ms->offset = -1;
ms->flags = 0;
ms->mflags = 0;
monitor_create (&(ms->lock));
ms->base.vtable = &_map_vtable;
*pstream = &ms->base;
return 0;
......
......@@ -27,41 +27,23 @@
#include <mailutils/sys/memstream.h>
static int
_memory_add_ref (stream_t stream)
_memory_ref (stream_t stream)
{
int status;
struct _memory_stream *mem = (struct _memory_stream *)stream;
monitor_lock (mem->lock);
status = ++mem->ref;
monitor_unlock (mem->lock);
return status;
return mu_refcount_inc (mem->refcount);
}
static int
_memory_destroy (stream_t stream)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
if (mem && mem->ptr != NULL)
free (mem->ptr);
free (mem);
return 0;
}
static int
_memory_release (stream_t stream)
static void
_memory_destroy (stream_t *pstream)
{
int status;
struct _memory_stream *mem = (struct _memory_stream *)stream;
monitor_lock (mem->lock);
status = --mem->ref;
if (status <= 0)
struct _memory_stream *mem = (struct _memory_stream *)*pstream;
if (mu_refcount_dec (mem->refcount) == 0)
{
monitor_unlock (mem->lock);
_memory_destroy (stream);
return 0;
if (mem && mem->ptr != NULL)
free (mem->ptr);
mu_refcount_destroy (&mem->refcount);
free (mem);
}
monitor_unlock (mem->lock);
return status;
}
static int
......@@ -69,6 +51,8 @@ _memory_read (stream_t stream, void *optr, size_t osize, size_t *nbytes)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
size_t n = 0;
mu_refcount_lock (mem->refcount);
if (mem->ptr != NULL && (mem->offset < (off_t)mem->size))
{
n = ((mem->offset + osize) > mem->size) ?
......@@ -76,6 +60,7 @@ _memory_read (stream_t stream, void *optr, size_t osize, size_t *nbytes)
memcpy (optr, mem->ptr + mem->offset, n);
mem->offset += n;
}
mu_refcount_unlock (mem->refcount);
if (nbytes)
*nbytes = n;
return 0;
......@@ -87,6 +72,7 @@ _memory_readline (stream_t stream, char *optr, size_t osize, size_t *nbytes)
struct _memory_stream *mem = (struct _memory_stream *)stream;
char *nl;
size_t n = 0;
mu_refcount_lock (mem->refcount);
if (mem->ptr && (mem->offset < (off_t)mem->size))
{
/* Save space for the null byte. */
......@@ -98,6 +84,7 @@ _memory_readline (stream_t stream, char *optr, size_t osize, size_t *nbytes)
optr[n] = '\0';
mem->offset += n;
}
mu_refcount_unlock (mem->refcount);
if (nbytes)
*nbytes = n;
return 0;
......@@ -108,6 +95,7 @@ _memory_write (stream_t stream, const void *iptr, size_t isize, size_t *nbytes)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
mu_refcount_lock (mem->refcount);
/* Bigger we have to realloc. */
if (mem->size < (mem->offset + isize))
{
......@@ -120,6 +108,7 @@ _memory_write (stream_t stream, const void *iptr, size_t isize, size_t *nbytes)
memcpy (mem->ptr + mem->offset, iptr, isize);
mem->offset += isize;
mu_refcount_unlock (mem->refcount);
if (nbytes)
*nbytes = isize;
return 0;
......@@ -130,6 +119,7 @@ _memory_truncate (stream_t stream, off_t len)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
mu_refcount_lock (mem->refcount);
if (len == 0)
{
free (mem->ptr);
......@@ -144,6 +134,7 @@ _memory_truncate (stream_t stream, off_t len)
}
mem->size = len;
mem->offset = len;
mu_refcount_unlock (mem->refcount);
return 0;
}
......@@ -151,8 +142,10 @@ static int
_memory_get_size (stream_t stream, off_t *psize)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
mu_refcount_lock (mem->refcount);
if (psize)
*psize = mem->size;
mu_refcount_unlock (mem->refcount);
return 0;
}
......@@ -160,11 +153,13 @@ static int
_memory_close (stream_t stream)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
mu_refcount_lock (mem->refcount);
if (mem->ptr)
free (mem->ptr);
mem->ptr = NULL;
mem->size = 0;
mem->offset = 0;
mu_refcount_unlock (mem->refcount);
return 0;
}
......@@ -278,6 +273,7 @@ _memory_open (stream_t stream, const char *filename, int port, int flags)
(void)filename; /* Ignored. */
(void)flags; /* Ignored. */
mu_refcount_lock (mem->refcount);
/* Close any previous file. */
if (mem->ptr)
free (mem->ptr);
......@@ -285,13 +281,13 @@ _memory_open (stream_t stream, const char *filename, int port, int flags)
mem->size = 0;
mem->offset = 0;
mem->flags = flags;
mu_refcount_unlock (mem->refcount);
return 0;
}
static struct _stream_vtable _mem_vtable =
{
_memory_add_ref,
_memory_release,
_memory_ref,
_memory_destroy,
_memory_open,
......@@ -331,14 +327,17 @@ stream_memory_create (stream_t *pstream)
if (mem == NULL)
return MU_ERROR_NO_MEMORY;
mem->base.vtable = &_mem_vtable;
mem->ref = 1;
mu_refcount_create (&mem->refcount);
if (mem->refcount == NULL)
{
free (mem);
return MU_ERROR_NO_MEMORY;
}
mem->ptr = NULL;
mem->size = 0;
mem->offset = 0;
mem->flags = 0;
monitor_create (&(mem->lock));
mem->base.vtable = &_mem_vtable;
*pstream = &mem->base;
return 0;
}
......
......@@ -24,30 +24,24 @@
#include <mailutils/sys/message.h>
int
message_add_ref (message_t msg)
message_ref (message_t msg)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->add_ref == NULL)
|| msg->vtable->ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->add_ref (msg);
return msg->vtable->ref (msg);
}
int
message_release (message_t msg)
void
message_destroy (message_t *pmsg)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->release (msg);
}
int
message_destroy (message_t msg)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->destroy (msg);
if (pmsg && *pmsg)
{
message_t msg = *pmsg;
if (msg->vtable && msg->vtable->destroy)
msg->vtable->destroy (pmsg);
*pmsg = NULL;
}
}
int
......
......@@ -329,14 +329,14 @@ util_cpystr (char *dst, const char *src, size_t size)
return len;
}
static list_t _app_getpwnam = NULL;
static mu_list_t _app_getpwnam = NULL;
void
mu_register_getpwnam (struct passwd *(*fun) __P((const char *)))
{
if (!_app_getpwnam && list_create (&_app_getpwnam))
if (!_app_getpwnam && mu_list_create (&_app_getpwnam))
return;
list_append (_app_getpwnam, fun);
mu_list_append (_app_getpwnam, fun);
}
struct passwd *
......@@ -347,7 +347,7 @@ mu_getpwnam (const char *name)
p = getpwnam (name);
if (!p && iterator_create (&itr, _app_getpwnam) == 0)
if (p && mu_list_get_iterator (_app_getpwnam, &itr) == 0)
{
struct passwd *(*fun) __P((const char *));
for (iterator_first (itr); !p && !iterator_is_done (itr);
......@@ -356,7 +356,6 @@ mu_getpwnam (const char *name)
iterator_current (itr, (void **)&fun);
p = (*fun) (name);
}
iterator_destroy (&itr);
}
return p;
......
......@@ -51,18 +51,12 @@ observable_create (observable_t *pobservable)
return 0;
}
int
observable_release (observable_t observable)
{
(void)observable;
return 1;
}
int
observable_destroy (observable_t observable)
void
observable_destroy (observable_t *pobservable)
{
if (observable)
if (pobservable && *pobservable)
{
observable_t observable = *pobservable;
iterator_t iterator = NULL;
int status = mu_list_get_iterator (observable->list, &iterator);
if (status == 0)
......@@ -75,16 +69,16 @@ observable_destroy (observable_t observable)
iterator_current (iterator, (void **)&info);
if (info)
{
observer_release (info->observer);
observer_destroy (&info->observer);
free (info);
}
}
iterator_release (iterator);
iterator_destroy (&iterator);
}
mu_list_destroy (observable->list);
mu_list_destroy (&observable->list);
free (observable);
*pobservable = NULL;
}
return 0;
}
int
......@@ -124,7 +118,7 @@ observable_detach (observable_t observable, observer_t observer)
break;
}
}
iterator_release (iterator);
iterator_destroy (&iterator);
if (found)
{
status = mu_list_remove (observable->list, info);
......@@ -155,6 +149,6 @@ observable_notify_all (observable_t observable, struct event evt)
status |= observer_action (info->observer, evt);
}
}
iterator_release (iterator);
iterator_destroy (&iterator);
return status;
}
......
......@@ -25,34 +25,28 @@
#include <mailutils/sys/observer.h>
int
(observer_add_ref) (observer_t observer)
observer_ref (observer_t observer)
{
if (observer == NULL || observer->vtable == NULL
|| observer->vtable->add_ref == NULL)
|| observer->vtable->ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return observer->vtable->add_ref (observer);
return observer->vtable->ref (observer);
}
int
(observer_release) (observer_t observer)
{
if (observer == NULL || observer->vtable == NULL
|| observer->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return observer->vtable->release (observer);
}
int
(observer_destroy) (observer_t observer)
void
observer_destroy (observer_t *pobserver)
{
if (observer == NULL || observer->vtable == NULL
|| observer->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return observer->vtable->destroy (observer);
if (pobserver && *pobserver)
{
observer_t observer = *pobserver;
if (observer->vtable || observer->vtable->destroy)
observer->vtable->destroy (pobserver);
*pobserver = NULL;
}
}
int
(observer_action) (observer_t observer, struct event evt)
observer_action (observer_t observer, struct event evt)
{
if (observer == NULL || observer->vtable == NULL
|| observer->vtable->action == NULL)
......@@ -63,39 +57,21 @@ int
static int
_dobserver_add_ref (observer_t observer)
_dobserver_ref (observer_t observer)
{
struct _dobserver *dobserver = (struct _dobserver *)observer;
int status;
monitor_lock (dobserver->lock);
status = ++dobserver->ref;
monitor_unlock (dobserver->lock);
return status;
return mu_refcount_inc (dobserver->refcount);
}
static int
_dobserver_destroy (observer_t observer)
static void
_dobserver_destroy (observer_t *pobserver)
{
struct _dobserver *dobserver = (struct _dobserver *)observer;
monitor_destroy (dobserver->lock);
free (dobserver);
return 0;
}
static int
_dobserver_release (observer_t observer)
{
int status;
struct _dobserver *dobserver = (struct _dobserver *)observer;
monitor_lock (dobserver->lock);
status = --dobserver->ref;
if (status <= 0)
struct _dobserver *dobserver = (struct _dobserver *)*pobserver;
if (mu_refcount_dec (dobserver->refcount) == 0)
{
monitor_unlock (dobserver->lock);
return _dobserver_destroy (observer);
mu_refcount_destroy (&dobserver->refcount);
free (dobserver);
}
monitor_unlock (dobserver->lock);
return status;
}
static int
......@@ -109,8 +85,7 @@ _dobserver_action (observer_t observer, struct event evt)
static struct _observer_vtable _dobserver_vtable =
{
_dobserver_add_ref,
_dobserver_release,
_dobserver_ref,
_dobserver_destroy,
_dobserver_action
......@@ -130,11 +105,15 @@ observer_create (observer_t *pobserver,
if (dobserver)
return MU_ERROR_NO_MEMORY;
dobserver->base.vtable = &_dobserver_vtable;
dobserver->ref = 1;
mu_refcount_create (&dobserver->refcount);
if (dobserver->refcount == NULL)
{
free (dobserver);
return MU_ERROR_NO_MEMORY;
}
dobserver->arg = arg;
dobserver->action = action;
monitor_create (&(dobserver->lock));
dobserver->base.vtable = &_dobserver_vtable;
*pobserver = &dobserver->base;
return 0;
}
......
......@@ -671,7 +671,7 @@ int parse822_address_list(address_t* a, const char* s)
}
if(rc) {
address_destroy(*a);
address_destroy(a);
}
return rc;
......@@ -754,7 +754,7 @@ int parse822_group(const char** p, const char* e, address_t* a)
if(rc || (rc = parse822_special(p, e, ';'))) {
*p = save;
address_destroy(*asave);
address_destroy(asave);
}
return rc;
......@@ -785,7 +785,7 @@ int parse822_mail_box(const char** p, const char* e, address_t* a)
}
/* but if something else is wrong, destroy the address */
if(rc) {
address_destroy(*a);
address_destroy(a);
*p = save;
}
......@@ -854,7 +854,7 @@ int parse822_route_addr(const char** p, const char* e, address_t* a)
if((rc = parse822_special(p, e, '>'))) {
*p = save;
address_destroy(*a);
address_destroy(a);
return rc;
}
......
......@@ -37,7 +37,7 @@ pop3_set_carrier (pop3_t pop3, stream_t carrier)
if (pop3->carrier)
{
stream_close (pop3->carrier);
stream_release (pop3->carrier);
stream_destroy (&pop3->carrier);
}
pop3->carrier = carrier;
return 0;
......@@ -59,12 +59,10 @@ pop3_get_carrier (pop3_t pop3, stream_t *pcarrier)
status = stream_buffer_create (&(pop3->carrier), carrier, 1024);
if (status != 0)
{
stream_release (carrier);
stream_destroy (&carrier);
return status;
}
}
/* Incremente the ref count, since we are exposing it. */
stream_add_ref (pop3->carrier);
*pcarrier = pop3->carrier;
return 0;
}
......
......@@ -60,8 +60,6 @@ pop3_connect (pop3_t pop3, const char *host, unsigned int port)
stream_t carrier;
status = pop3_get_carrier (pop3, &carrier);
POP3_CHECK_ERROR (pop3, status);
/* A add_ref was done part of pop3_get_carrier(). */
stream_release (carrier);
}
else
{
......
......@@ -46,7 +46,7 @@ pop3_create (pop3_t *ppop3)
pop3->ack.buf = calloc (pop3->ack.len, 1);
if (pop3->ack.buf == NULL)
{
pop3_destroy (pop3);
pop3_destroy (&pop3);
return MU_ERROR_NO_MEMORY;
}
pop3->ack.ptr = pop3->ack.buf;
......@@ -56,7 +56,7 @@ pop3_create (pop3_t *ppop3)
pop3->io.buf = calloc (pop3->io.len, 1);
if (pop3->io.buf == NULL)
{
pop3_destroy (pop3);
pop3_destroy (&pop3);
return MU_ERROR_NO_MEMORY;
}
pop3->io.ptr = pop3->io.buf;
......
......@@ -23,11 +23,12 @@
#include <mailutils/sys/pop3.h>
#include <stdlib.h>
int
pop3_destroy (pop3_t pop3)
void
pop3_destroy (pop3_t *ppop3)
{
if (pop3)
if (ppop3 && *ppop3)
{
pop3_t pop3 = *ppop3;
if (pop3->ack.buf)
free (pop3->ack.buf);
......@@ -37,7 +38,10 @@ pop3_destroy (pop3_t pop3)
if (pop3->timestamp)
free (pop3->timestamp);
if (pop3->carrier)
stream_destroy (&pop3->carrier);
free (pop3);
*ppop3 = NULL;
}
return 0;
}
......
......@@ -26,19 +26,17 @@
#include <stdio.h>
#include <mailutils/sys/pop3.h>
static int p_add_ref __P ((iterator_t));
static int p_release __P ((iterator_t));
static int p_destroy __P ((iterator_t));
static int p_first __P ((iterator_t));
static int p_next __P ((iterator_t));
static int p_current __P ((iterator_t, void *));
static int p_is_done __P ((iterator_t));
static int p_ref __P ((iterator_t));
static void p_destroy __P ((iterator_t *));
static int p_first __P ((iterator_t));
static int p_next __P ((iterator_t));
static int p_current __P ((iterator_t, void *));
static int p_is_done __P ((iterator_t));
static struct _iterator_vtable p_i_vtable =
{
/* Base. */
p_add_ref,
p_release,
p_ref,
p_destroy,
p_first,
......@@ -56,55 +54,32 @@ pop3_iterator_create (pop3_t pop3, iterator_t *piterator)
if (p_iterator == NULL)
return MU_ERROR_NO_MEMORY;
p_iterator->base.vtable = &p_i_vtable;
p_iterator->ref = 1;
mu_refcount_create (&p_iterator->refcount);
if (p_iterator->refcount == NULL)
{
free (p_iterator);
return MU_ERROR_NO_MEMORY;
}
p_iterator->item = NULL;
p_iterator->done = 0;
p_iterator->pop3= pop3;
monitor_create (&p_iterator->lock);
p_iterator->base.vtable = &p_i_vtable;
*piterator = &p_iterator->base;
return 0;
}
static int
p_add_ref (iterator_t iterator)
{
int status = 0;
struct p_iterator *p_iterator = (struct p_iterator *)iterator;
if (p_iterator)
{
monitor_lock (p_iterator->lock);
status = ++p_iterator->ref;
monitor_unlock (p_iterator->lock);
}
return status;
}
static int
p_release (iterator_t iterator)
p_ref (iterator_t iterator)
{
int status = 0;
struct p_iterator *p_iterator = (struct p_iterator *)iterator;
if (p_iterator)
{
monitor_lock (p_iterator->lock);
status = --p_iterator->ref;
if (status <= 0)
{
monitor_unlock (p_iterator->lock);
p_destroy (iterator);
return 0;
}
monitor_unlock (p_iterator->lock);
}
return status;
return mu_refcount_inc (p_iterator->refcount);
}
static int
p_destroy (iterator_t iterator)
static void
p_destroy (iterator_t *piterator)
{
struct p_iterator *p_iterator = (struct p_iterator *)iterator;
if (p_iterator)
struct p_iterator *p_iterator = (struct p_iterator *)*piterator;
if (mu_refcount_dec (p_iterator->refcount) == 0)
{
if (!p_iterator->done)
{
......@@ -117,10 +92,9 @@ p_destroy (iterator_t iterator)
if (p_iterator->item)
free (p_iterator->item);
p_iterator->pop3->state = POP3_NO_STATE;
monitor_destroy (p_iterator->lock);
mu_refcount_destroy (&p_iterator->refcount);
free (p_iterator);
}
return 0;
}
static int
......@@ -138,7 +112,7 @@ p_next (iterator_t iterator)
if (p_iterator)
{
monitor_lock (p_iterator->lock);
mu_refcount_lock (p_iterator->refcount);
if (!p_iterator->done)
{
/* The first readline will not consume the buffer, we just need to
......@@ -170,7 +144,7 @@ p_next (iterator_t iterator)
}
}
}
monitor_unlock (p_iterator->lock);
mu_refcount_unlock (p_iterator->refcount);
}
return status;
}
......@@ -182,9 +156,9 @@ p_is_done (iterator_t iterator)
int status = 1;
if (p_iterator)
{
monitor_lock (p_iterator->lock);
mu_refcount_lock (p_iterator->refcount);
status = p_iterator->done;
monitor_unlock (p_iterator->lock);
mu_refcount_unlock (p_iterator->refcount);
}
return status;
}
......@@ -195,13 +169,13 @@ p_current (iterator_t iterator, void *item)
struct p_iterator *p_iterator = (struct p_iterator *)iterator;
if (p_iterator)
{
monitor_lock (p_iterator->lock);
mu_refcount_lock (p_iterator->refcount);
if (item)
{
*((char **)item) = p_iterator->item;
p_iterator->item = NULL;
}
monitor_unlock (p_iterator->lock);
mu_refcount_unlock (p_iterator->refcount);
}
return 0;
}
......
......@@ -28,38 +28,36 @@
#include <mailutils/sys/pop3.h>
/* Implementation of the stream for TOP and RETR. */
static int p_add_ref __P ((stream_t));
static int p_release __P ((stream_t));
static int p_destroy __P ((stream_t));
static int p_ref __P ((stream_t));
static void p_destroy __P ((stream_t *));
static int p_open __P ((stream_t, const char *, int, int));
static int p_close __P ((stream_t));
static int p_open __P ((stream_t, const char *, int, int));
static int p_close __P ((stream_t));
static int p_read __P ((stream_t, void *, size_t, size_t *));
static int p_readline __P ((stream_t, char *, size_t, size_t *));
static int p_write __P ((stream_t, const void *, size_t, size_t *));
static int p_read __P ((stream_t, void *, size_t, size_t *));
static int p_readline __P ((stream_t, char *, size_t, size_t *));
static int p_write __P ((stream_t, const void *, size_t, size_t *));
static int p_seek __P ((stream_t, off_t, enum stream_whence));
static int p_tell __P ((stream_t, off_t *));
static int p_seek __P ((stream_t, off_t, enum stream_whence));
static int p_tell __P ((stream_t, off_t *));
static int p_get_size __P ((stream_t, off_t *));
static int p_truncate __P ((stream_t, off_t));
static int p_flush __P ((stream_t));
static int p_get_size __P ((stream_t, off_t *));
static int p_truncate __P ((stream_t, off_t));
static int p_flush __P ((stream_t));
static int p_get_fd __P ((stream_t, int *));
static int p_get_flags __P ((stream_t, int *));
static int p_get_state __P ((stream_t, enum stream_state *));
static int p_get_fd __P ((stream_t, int *));
static int p_get_flags __P ((stream_t, int *));
static int p_get_state __P ((stream_t, enum stream_state *));
static int p_is_readready __P ((stream_t, int timeout));
static int p_is_writeready __P ((stream_t, int timeout));
static int p_is_exceptionpending __P ((stream_t, int timeout));
static int p_is_readready __P ((stream_t, int timeout));
static int p_is_writeready __P ((stream_t, int timeout));
static int p_is_exceptionpending __P ((stream_t, int timeout));
static int p_is_open __P ((stream_t));
static int p_is_open __P ((stream_t));
static struct _stream_vtable p_s_vtable =
{
p_add_ref,
p_release,
p_ref,
p_destroy,
p_open,
......@@ -96,50 +94,32 @@ pop3_stream_create (pop3_t pop3, stream_t *pstream)
if (p_stream == NULL)
return MU_ERROR_NO_MEMORY;
p_stream->base.vtable = &p_s_vtable;
p_stream->ref = 1;
mu_refcount_create (&p_stream->refcount);
if (p_stream->refcount == NULL)
{
free (p_stream);
return MU_ERROR_NO_MEMORY;
}
p_stream->done = 0;
p_stream->pop3 = pop3;
monitor_create (&p_stream->lock);
p_stream->base.vtable = &p_s_vtable;
*pstream = &p_stream->base;
return 0;
}
static int
p_add_ref (stream_t stream)
p_ref (stream_t stream)
{
struct p_stream *p_stream = (struct p_stream *)stream;
int status = 0;
if (p_stream)
{
monitor_lock (p_stream->lock);
status = ++p_stream->ref;
monitor_unlock (p_stream->lock);
}
return status;
return mu_refcount_inc (p_stream->refcount);
}
static int
p_release (stream_t stream)
static void
p_destroy (stream_t *pstream)
{
struct p_stream *p_stream = (struct p_stream *)stream;
int status = 0;
if (p_stream)
{
monitor_lock (p_stream->lock);
status = --p_stream->ref;
if (status <= 0)
p_destroy (stream);
monitor_unlock (p_stream->lock);
}
return status;
}
static int
p_destroy (stream_t stream)
{
struct p_stream *p_stream = (struct p_stream *)stream;
if (p_stream)
struct p_stream *p_stream = (struct p_stream *)*pstream;
if (mu_refcount_dec (p_stream->refcount) == 0)
{
if (!p_stream->done)
{
......@@ -150,10 +130,9 @@ p_destroy (stream_t stream)
n = 0;
}
p_stream->pop3->state = POP3_NO_STATE;
monitor_destroy (p_stream->lock);
mu_refcount_destroy (&p_stream->refcount);
free (p_stream);
}
return 0;
}
static int
......@@ -180,7 +159,7 @@ p_read (stream_t stream, void *buf, size_t buflen, size_t *pn)
char *p = buf;
if (p_stream)
{
monitor_lock (p_stream->lock);
mu_refcount_lock (p_stream->refcount);
if (!p_stream->done)
{
do
......@@ -215,7 +194,7 @@ p_read (stream_t stream, void *buf, size_t buflen, size_t *pn)
}
while (buflen > 0);
}
monitor_unlock (p_stream->lock);
mu_refcount_unlock (p_stream->refcount);
}
if (pn)
*pn = n;
......@@ -230,7 +209,7 @@ p_readline (stream_t stream, char *buf, size_t buflen, size_t *pn)
int status = 0;
if (p_stream)
{
monitor_lock (p_stream->lock);
mu_refcount_lock (p_stream->refcount);
if (!p_stream->done)
{
status = pop3_readline (p_stream->pop3, buf, buflen, &n);
......@@ -240,7 +219,7 @@ p_readline (stream_t stream, char *buf, size_t buflen, size_t *pn)
p_stream->done = 1;
}
}
monitor_unlock (p_stream->lock);
mu_refcount_unlock (p_stream->refcount);
}
if (pn)
*pn = n;
......
......@@ -352,7 +352,7 @@ com_capa (char *arg)
printf ("Capa: %s\n", capa);
free (capa);
}
iterator_destroy (iterator);
iterator_destroy (&iterator);
}
return status;
}
......@@ -377,7 +377,7 @@ com_uidl (char *arg)
printf ("Msg: %d UIDL: %s\n", msgno, uidl);
free (uidl);
}
iterator_destroy (uidl_iterator);
iterator_destroy (&uidl_iterator);
}
}
else
......@@ -411,7 +411,7 @@ com_list (char *arg)
pop3_list_current (list_iterator, &msgno, &size);
printf ("Msg: %d Size: %d\n", msgno, size);
}
iterator_destroy (list_iterator);
iterator_destroy (&list_iterator);
}
}
else
......@@ -577,7 +577,7 @@ com_top (char *arg)
char buf[128];
while ((stream_readline (stream, buf, sizeof buf, &n) == 0) && n)
printf ("%s", buf);
stream_destroy (stream);
stream_destroy (&stream);
}
return 0;
}
......@@ -602,7 +602,7 @@ com_retr (char *arg)
char buf[128];
while ((stream_readline (stream, buf, sizeof buf, &n) == 0) && n)
printf ("%s", buf);
stream_destroy (stream);
stream_destroy (&stream);
}
return 0;
}
......@@ -639,7 +639,7 @@ com_disconnect (char *arg)
if (pop3)
{
pop3_disconnect (pop3);
pop3_destroy (pop3);
pop3_destroy (&pop3);
pop3 = NULL;
}
return 0;
......@@ -674,7 +674,7 @@ com_exit (char *arg)
if (pop3)
{
pop3_disconnect (pop3);
pop3_destroy (pop3);
pop3_destroy (&pop3);
}
done = 1;
return 0;
......
......@@ -26,14 +26,14 @@
#include <termios.h>
#include <mailutils/error.h>
#include <mailutils/monitor.h>
#include <mailutils/refcount.h>
#include <mailutils/sys/ticket.h>
struct _prompt_ticket
{
struct _ticket base;
int ref;
monitor_t lock;
mu_refcount_t refcount;
};
static void
......@@ -53,40 +53,21 @@ echo_on(struct termios *stored_settings)
}
static int
_prompt_add_ref (ticket_t ticket)
_prompt_ref (ticket_t ticket)
{
int status;
struct _prompt_ticket *prompt = (struct _prompt_ticket *)ticket;
monitor_lock (prompt->lock);
status = ++prompt->ref;
monitor_unlock (prompt->lock);
return status;
return mu_refcount_inc (prompt->refcount);
}
static int
_prompt_destroy (ticket_t ticket)
{
struct _prompt_ticket *prompt = (struct _prompt_ticket *)ticket;
monitor_destroy (prompt->lock);
free (prompt);
return 0;
}
static int
_prompt_release (ticket_t ticket)
static void
_prompt_destroy (ticket_t *pticket)
{
int status;
struct _prompt_ticket *prompt = (struct _prompt_ticket *)ticket;
monitor_lock (prompt->lock);
status = --prompt->ref;
if (status <= 0)
struct _prompt_ticket *prompt = (struct _prompt_ticket *)*pticket;
if (mu_refcount_dec (prompt->refcount) == 0)
{
monitor_unlock (prompt->lock);
_prompt_destroy (ticket);
return 0;
mu_refcount_destroy (&prompt->refcount);
free (prompt);
}
monitor_unlock (prompt->lock);
return status;
}
static int
......@@ -119,8 +100,7 @@ _prompt_pop (ticket_t ticket, const char *challenge, char **parg)
static struct _ticket_vtable _prompt_vtable =
{
_prompt_add_ref,
_prompt_release,
_prompt_ref,
_prompt_destroy,
_prompt_pop,
......@@ -138,10 +118,14 @@ ticket_prompt_create (ticket_t *pticket)
if (prompt == NULL)
return MU_ERROR_NO_MEMORY;
prompt->base.vtable = &_prompt_vtable;
prompt->ref = 1;
monitor_create (&(prompt->lock));
mu_refcount_create (&prompt->refcount);
if (prompt->refcount == NULL)
{
free (prompt);
return MU_ERROR_NO_MEMORY;
}
*pticket = &prompt->base;
prompt->base.vtable = &_prompt_vtable;
return 0;
}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
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 <stdlib.h>
#include <mailutils/monitor.h>
#include <mailutils/error.h>
#include <mailutils/sys/refcount.h>
int
mu_refcount_create (mu_refcount_t *prefcount)
{
mu_refcount_t refcount;
if (prefcount == NULL)
return MU_ERROR_INVALID_PARAMETER;
refcount = calloc (1, sizeof *refcount);
if (refcount == NULL)
return MU_ERROR_NO_MEMORY;
refcount->ref = 1;
monitor_create (&(refcount->lock));
*prefcount = refcount;
return 0;
}
void
mu_refcount_destroy (mu_refcount_t *prefcount)
{
if (prefcount && *prefcount)
{
mu_refcount_t refcount = *prefcount;
monitor_destroy (&refcount->lock);
free (refcount);
*prefcount = NULL;
}
}
int
mu_refcount_lock (mu_refcount_t refcount)
{
if (refcount)
return monitor_lock (refcount->lock);
return 0;
}
int
mu_refcount_unlock (mu_refcount_t refcount)
{
if (refcount)
return monitor_unlock (refcount->lock);
return 0;
}
int
mu_refcount_inc (mu_refcount_t refcount)
{
int count = 0;
if (refcount)
{
monitor_lock (refcount->lock);
count = ++refcount->ref;
monitor_unlock (refcount->lock);
}
return count;
}
int
mu_refcount_dec (mu_refcount_t refcount)
{
int count = 0;
if (refcount)
{
monitor_lock (refcount->lock);
if (refcount->ref)
count = --refcount->ref;
monitor_unlock (refcount->lock);
}
return count;
}
......@@ -24,30 +24,24 @@
#include <mailutils/sys/stream.h>
int
stream_add_ref (stream_t stream)
stream_ref (stream_t stream)
{
if (stream == NULL || stream->vtable == NULL
|| stream->vtable->add_ref == NULL)
|| stream->vtable->ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return stream->vtable->add_ref (stream);
return stream->vtable->ref (stream);
}
int
stream_release (stream_t stream)
{
if (stream == NULL || stream->vtable == NULL
|| stream->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return stream->vtable->release (stream);
}
int
stream_destroy (stream_t stream)
void
stream_destroy (stream_t *pstream)
{
if (stream == NULL || stream->vtable == NULL
|| stream->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return stream->vtable->destroy (stream);
if (pstream && *pstream)
{
stream_t stream = *pstream;
if (stream->vtable && stream->vtable->destroy)
stream->vtable->destroy (pstream);
*pstream = NULL;
}
}
int
......@@ -158,7 +152,6 @@ stream_get_flags (stream_t stream, int *flags)
return stream->vtable->get_flags (stream, flags);
}
int
stream_get_state (stream_t stream, enum stream_state *state)
{
......
......@@ -32,11 +32,10 @@
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <mailutils/sys/tcpstream.h>
#include <mailutils/error.h>
#include <mailutils/monitor.h>
/* On solaris inet_addr() return -1. */
#ifndef INADDR_NONE
......@@ -47,48 +46,29 @@ static void
_tcp_cleanup (void *arg)
{
struct _tcp_instance *tcp = arg;
monitor_unlock (tcp->lock);
mu_refcount_unlock (tcp->refcount);
}
static int
_tcp_add_ref (stream_t stream)
_tcp_ref (stream_t stream)
{
struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
int status;
monitor_lock (tcp->lock);
status = ++tcp->ref;
monitor_unlock (tcp->lock);
return status;
return mu_refcount_inc (tcp->refcount);
}
static int
_tcp_destroy (stream_t stream)
{
struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
if (tcp->host)
free (tcp->host);
if (tcp->fd != -1)
close (tcp->fd);
monitor_destroy (tcp->lock);
free (tcp);
return 0;
}
static int
_tcp_release (stream_t stream)
static void
_tcp_destroy (stream_t *pstream)
{
int status;
struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
monitor_lock (tcp->lock);
status = --tcp->ref;
if (status <= 0)
struct _tcp_instance *tcp = (struct _tcp_instance *)*pstream;
if (mu_refcount_dec (tcp->refcount) == 0)
{
monitor_unlock (tcp->lock);
_tcp_destroy (stream);
return 0;
if (tcp->host)
free (tcp->host);
if (tcp->fd != -1)
close (tcp->fd);
mu_refcount_destroy (&tcp->refcount);
free (tcp);
}
monitor_unlock (tcp->lock);
return status;
}
static int
......@@ -107,10 +87,10 @@ _tcp_close (stream_t stream)
{
struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
monitor_lock (tcp->lock);
mu_refcount_lock (tcp->refcount);
monitor_cleanup_push (_tcp_cleanup, tcp);
_tcp_close0 (stream);
monitor_unlock (tcp->lock);
mu_refcount_unlock (tcp->refcount);
monitor_cleanup_pop (0);
return 0;
}
......@@ -168,12 +148,12 @@ _tcp_open0 (stream_t stream, const char *host, int port, int flags)
tcp->state = TCP_STATE_RESOLVE;
case TCP_STATE_RESOLVE:
memset (&soc_addr, 0, sizeof (soc_addr));
memset (&soc_addr, 0, sizeof soc_addr);
soc_addr.sin_family = AF_INET;
soc_addr.sin_port = htons (tcp->port);
soc_addr.sin_addr.s_addr = tcp->address;
if ((connect (tcp->fd, (struct sockaddr *)&soc_addr, sizeof (soc_addr))) == -1)
if ((connect (tcp->fd, (struct sockaddr *)&soc_addr, sizeof soc_addr)) == -1)
{
ret = errno;
if (ret == EINPROGRESS || ret == EAGAIN)
......@@ -188,7 +168,7 @@ _tcp_open0 (stream_t stream, const char *host, int port, int flags)
tcp->state = TCP_STATE_CONNECTING;
case TCP_STATE_CONNECTING:
namelen = sizeof (peer_addr);
namelen = sizeof peer_addr;
if (getpeername (tcp->fd, (struct sockaddr *)&peer_addr, &namelen) == 0)
tcp->state = TCP_STATE_CONNECTED;
else
......@@ -207,10 +187,10 @@ _tcp_open (stream_t stream, const char *host, int port, int flags)
{
int status;
struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
monitor_lock (tcp->lock);
mu_refcount_lock (tcp->refcount);
monitor_cleanup_push (_tcp_cleanup, tcp);
status = _tcp_open0 (stream, host, port, flags);
monitor_unlock (tcp->lock);
mu_refcount_unlock (tcp->refcount);
monitor_cleanup_pop (0);
return status;
}
......@@ -231,19 +211,18 @@ static int
_tcp_read (stream_t stream, void *buf, size_t buf_size, size_t *br)
{
struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
int bytes;
int bytes = 0;
int status = 0;
if (br == NULL)
return MU_ERROR_INVALID_PARAMETER;
*br = 0;
bytes = recv (tcp->fd, buf, buf_size, 0);
if (bytes == -1)
{
*br = 0;
return errno;
bytes = 0;
status = errno;
}
*br = bytes;
return 0;
if (br)
*br = bytes;
return status;
}
static int
......@@ -287,19 +266,18 @@ static int
_tcp_write (stream_t stream, const void *buf, size_t buf_size, size_t *bw)
{
struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
int bytes;
int bytes = 0;
int status = 0;
if (bw == NULL)
return MU_ERROR_INVALID_PARAMETER;
*bw = 0;
bytes = send (tcp->fd, buf, buf_size, 0);
if (bytes == -1)
{
*bw = 0;
return errno;
bytes = 0;
status = errno;
}
*bw = bytes;
return 0;
if (bw)
*bw = bytes;
return status;
}
static int
......@@ -420,8 +398,7 @@ _tcp_is_open (stream_t stream)
static struct _stream_vtable _tcp_vtable =
{
_tcp_add_ref,
_tcp_release,
_tcp_ref,
_tcp_destroy,
_tcp_open,
......@@ -461,13 +438,17 @@ stream_tcp_create (stream_t *pstream)
if (tcp == NULL)
return MU_ERROR_NO_MEMORY;
tcp->base.vtable = &_tcp_vtable;
tcp->ref = 1;
mu_refcount_create (&tcp->refcount);
if (tcp->refcount == NULL)
{
free (tcp);
return MU_ERROR_NO_MEMORY;
}
tcp->fd = -1;
tcp->host = NULL;
tcp->port = -1;
tcp->state = TCP_STATE_INIT;
monitor_create (&(tcp->lock));
tcp->base.vtable = &_tcp_vtable;
*pstream = &tcp->base;
return 0;
}
......
......@@ -24,30 +24,24 @@
#include <mailutils/sys/ticket.h>
int
ticket_add_ref (ticket_t ticket)
ticket_ref (ticket_t ticket)
{
if (ticket == NULL || ticket->vtable == NULL
|| ticket->vtable->add_ref == NULL)
|| ticket->vtable->ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return ticket->vtable->add_ref (ticket);
return ticket->vtable->ref (ticket);
}
int
ticket_release (ticket_t ticket)
void
ticket_destroy (ticket_t *pticket)
{
if (ticket == NULL || ticket->vtable == NULL
|| ticket->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return ticket->vtable->release (ticket);
}
int
ticket_destroy (ticket_t ticket)
{
if (ticket == NULL || ticket->vtable == NULL
|| ticket->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return ticket->vtable->destroy (ticket);
if (pticket && *pticket)
{
ticket_t ticket = *pticket;
if (ticket->vtable && ticket->vtable->destroy)
ticket->vtable->destroy (pticket);
*pticket = NULL;
}
}
int
......