summaryrefslogtreecommitdiff
path: root/libmailutils/base
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-11-18 20:27:18 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2010-11-18 21:21:52 +0200
commit77d2867d07ba9d1c5b8b0af1ba8b0543cf57f384 (patch)
tree7405ae2fa45219a5ce36ebba78e5038c09ce9817 /libmailutils/base
parent33a277e9f8e8541fee73f902413afb100e48b95c (diff)
downloadmailutils-77d2867d07ba9d1c5b8b0af1ba8b0543cf57f384.tar.gz
mailutils-77d2867d07ba9d1c5b8b0af1ba8b0543cf57f384.tar.bz2
Rewrite property support.
* configure.ac: Add libmailutils/property/Makefile to config files. * include/mailutils/property.h (mu_property_create) (mu_property_destroy): Change signature. (mu_property_get_owner): Remove. (mu_property_create_init) (mu_property_set_init, mu_property_set_init_data) (mu_property_ref, mu_property_unref) (mu_property_save): New protos. (mu_property_get_iterator) (mu_assoc_property_init): New protos. * include/mailutils/sys/property.h (property_item): Remove definition. (MU_PROP_INIT, MU_PROP_FILL, MU_PROP_MODIFIED): New flags. (_mu_property): Rewrite from scratch. (_mu_property_check): New proto. * libmailutils/property/Makefile.am: New file. * libmailutils/property/assocprop.c: New file. * libmailutils/property/create.c: New file. * libmailutils/property/propget.c: New file. * libmailutils/property/propitr.c: New file. * libmailutils/property/propset.c: New file. * libmailutils/Makefile.am (SUBDIRS): Add property. (libmailutils_la_LIBADD): Add property/libproperty.la. * libmailutils/base/property.c: Remove. * libmailutils/base/Makefile.am (libbase_la_SOURCES): Remove property.c * libmailutils/base/assoc.c (first): Avoid coredumping on empty hash table. * include/mailutils/folder.h (mu_folder_set_property) (mu_folder_get_property): New protos. * include/mailutils/sys/folder.h (_mu_folder) <property> <_get_property>: New members. * libmailutils/mailbox/folder.c (mu_folder_destroy): Destroy the property. (mu_folder_get_property) (mu_folder_set_property): New functions. * include/mailutils/mailbox.h (mu_mailbox_set_property): New proto. * libmailutils/mailbox/mailbox.c (mu_mailbox_set_property): New function. (mu_mailbox_get_property): Use _get_property method. * include/mailutils/mailer.h (mu_mailer_set_property): New proto. * include/mailutils/sys/mailer.h (_mu_mailer) <_get_property>: New member. * libmailutils/mailer/mailer.c (mu_mailer_set_property): New function. (mu_mailer_get_property): Use _get_property method. * include/mailutils/iterator.h (mu_iterator_set_dataptr): New proto. * include/mailutils/sys/iterator.h (_mu_iterator) <dataptr>: New method. * libmailutils/base/iterator.c (mu_iterator_set_dataptr): New function. (mu_iterator_current): Rewrite as a wrapper around mu_iterator_current_kv. (mu_iterator_current_kv): Use dataptr method (if defined) to extract the data pointer. * libmailutils/tests/prop.c: New file. * libmailutils/tests/prop.at: New file. * libmailutils/tests/Makefile.am (noinst_PROGRAMS): Add prop. (TESTSUITE_AT): Add prop.at. * libmailutils/tests/testsuite.at: Include prop.at.
Diffstat (limited to 'libmailutils/base')
-rw-r--r--libmailutils/base/Makefile.am1
-rw-r--r--libmailutils/base/assoc.c9
-rw-r--r--libmailutils/base/iterator.c22
-rw-r--r--libmailutils/base/property.c191
4 files changed, 25 insertions, 198 deletions
diff --git a/libmailutils/base/Makefile.am b/libmailutils/base/Makefile.am
index b4f208ed7..8160e04b3 100644
--- a/libmailutils/base/Makefile.am
+++ b/libmailutils/base/Makefile.am
@@ -52,7 +52,6 @@ libbase_la_SOURCES = \
opool.c\
parsedate.c\
permstr.c\
- property.c\
registrar.c\
refcount.c\
rfc2047.c\
diff --git a/libmailutils/base/assoc.c b/libmailutils/base/assoc.c
index b2e3f60fa..56b293b58 100644
--- a/libmailutils/base/assoc.c
+++ b/libmailutils/base/assoc.c
@@ -391,10 +391,11 @@ first (void *owner)
mu_assoc_t assoc = itr->assoc;
unsigned hash_max = hash_size[assoc->hash_num];
unsigned i;
-
- for (i = 0; i < hash_max; i++)
- if ((ASSOC_ELEM (assoc, i))->name)
- break;
+
+ if (assoc->tab)
+ for (i = 0; i < hash_max; i++)
+ if ((ASSOC_ELEM (assoc, i))->name)
+ break;
itr->index = i;
return 0;
}
diff --git a/libmailutils/base/iterator.c b/libmailutils/base/iterator.c
index 97f7b75e0..e4d1846f4 100644
--- a/libmailutils/base/iterator.c
+++ b/libmailutils/base/iterator.c
@@ -103,6 +103,15 @@ mu_iterator_set_itrctl (mu_iterator_t itr,
}
int
+mu_iterator_set_dataptr (mu_iterator_t itr, void *(*dataptr) (void *))
+{
+ if (!itr)
+ return EINVAL;
+ itr->dataptr = dataptr;
+ return 0;
+}
+
+int
mu_iterator_set_destroy (mu_iterator_t itr, int (*destroy) (mu_iterator_t, void *))
{
if (!itr)
@@ -202,14 +211,23 @@ mu_iterator_skip (mu_iterator_t iterator, ssize_t count)
int
mu_iterator_current (mu_iterator_t iterator, void **pitem)
{
- return iterator->getitem (iterator->owner, pitem, NULL);
+ return mu_iterator_current_kv (iterator, NULL, pitem);
}
int
mu_iterator_current_kv (mu_iterator_t iterator,
const void **pkey, void **pitem)
{
- return iterator->getitem (iterator->owner, (void**)pitem, pkey);
+ void *ptr;
+ int rc = iterator->getitem (iterator->owner, &ptr, pkey);
+ if (rc == 0)
+ {
+ if (iterator->dataptr)
+ *pitem = iterator->dataptr (ptr);
+ else
+ *pitem = ptr;
+ }
+ return rc;
}
int
diff --git a/libmailutils/base/property.c b/libmailutils/base/property.c
deleted file mode 100644
index eec0ddc0b..000000000
--- a/libmailutils/base/property.c
+++ /dev/null
@@ -1,191 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
- Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2010 Free
- Software Foundation, Inc.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 3 of the License, or (at your option) any later version.
-
- This library 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
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General
- Public License along with this library. If not, see
- <http://www.gnu.org/licenses/>. */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-
-#include <mailutils/sys/property.h>
-#include <mailutils/errno.h>
-#include <mailutils/assoc.h>
-#include <stdlib.h>
-
-static void
-prop_free_value (void *data)
-{
- struct property_item *item = data;
- free (item->value);
-}
-
-int
-mu_property_create (mu_property_t *pp, void *owner)
-{
- int rc;
- mu_property_t prop;
- if (pp == NULL)
- return MU_ERR_OUT_PTR_NULL;
- prop = calloc (1, sizeof *prop);
- if (prop == NULL)
- return ENOMEM;
- rc = mu_assoc_create (&prop->assoc, sizeof (struct property_item), 0);
- if (rc)
- {
- free (prop);
- return rc;
- }
- mu_assoc_set_free (prop->assoc, prop_free_value);
- mu_monitor_create (&prop->lock, 0, prop);
- prop->owner = owner;
- *pp = prop;
- return 0;
-}
-
-void
-mu_property_destroy (mu_property_t *pp, void *owner)
-{
- if (pp && *pp)
- {
- mu_property_t prop = *pp;
- if (prop->owner == owner)
- {
- /* Destroy the list and is properties. */
- mu_monitor_wrlock (prop->lock);
- mu_assoc_destroy (&prop->assoc);
- mu_monitor_unlock (prop->lock);
- mu_monitor_destroy (&prop->lock, prop);
- free (prop);
- }
- *pp = NULL;
- }
-}
-
-void *
-mu_property_get_owner (mu_property_t prop)
-{
- return (prop == NULL) ? NULL : prop->owner;
-}
-
-int
-mu_property_set_value (mu_property_t prop, const char *key, const char *value,
- int overwrite)
-{
- struct property_item *item;
- int rc;
-
- if (!prop)
- return EINVAL;
- rc = mu_assoc_ref_install (prop->assoc, key, (void **)&item);
- if (rc == MU_ERR_NOENT)
- {
- item->value = strdup (value);
- }
- else if (overwrite)
- {
- free (item->value);
- item->value = strdup (value);
- }
- else
- return 0;
-
- if (!item->value)
- {
- mu_assoc_remove (prop->assoc, key);
- return ENOMEM;
- }
-
- return 0;
-}
-
-int
-mu_property_sget_value (mu_property_t prop, const char *key,
- const char **buffer)
-{
- struct property_item *item;
-
- if (!prop)
- return EINVAL;
- item = mu_assoc_ref (prop->assoc, key);
- if (item == NULL)
- return MU_ERR_NOENT;
- if (buffer)
- *buffer = item->value;
- return 0;
-}
-
-int
-mu_property_aget_value (mu_property_t prop, const char *key,
- char **buffer)
-{
- const char *value;
- int rc = mu_property_sget_value (prop, key, &value);
- if (rc == 0)
- {
- if ((*buffer = strdup (value)) == NULL)
- return ENOMEM;
- }
- return rc;
-}
-
-int
-mu_property_get_value (mu_property_t prop, const char *key, char *buffer,
- size_t buflen, size_t *n)
-{
- size_t len = 0;
- const char *value;
- int rc = mu_property_sget_value (prop, key, &value);
- if (rc == 0)
- {
- len = strlen (value) + 1;
- if (buffer && buflen)
- {
- if (buflen < len)
- len = buflen;
- len--;
- memcpy (buffer, value, len);
- buffer[len] = 0;
- }
- }
- if (n)
- *n = len;
- return rc;
-}
-
-int
-mu_property_is_set (mu_property_t prop, const char *key)
-{
- struct property_item *item = mu_assoc_ref (prop->assoc, key);
- return (item == NULL) ? 0 : 1;
-}
-
-int
-mu_property_set (mu_property_t prop, const char *key)
-{
- return mu_property_set_value (prop, key, "", 1);
-}
-
-int
-mu_property_unset (mu_property_t prop, const char *key)
-{
- if (!prop)
- return EINVAL;
- return mu_assoc_remove (prop->assoc, key);
-}
-

Return to:

Send suggestions and report system problems to the System administrator.