Commit 9b87545a 9b87545a76b9bfa7dba19f0b7c92293c7483ec00 by Alain Magloire

The code for property.c has been change for a more simple approach,

	it is the same approach as in mail/util.c(environment) settings.
	The old code was simply overkill, property_t was seldomly use
	if at all and no need for heavy hash table and all that jazz.

	* mailbox/property.c:  New code, the same as mail/util.c
	environment.
	* mailbox/mbx_mbox.c (_mbx_init): Remove property_add_defaults() etc ..
	no longer in use in the initialisation code.
	* mailbox/mbx_imap.c: Likewised
	* mailbox/mbx_pop.c: Likewised
	* mailbox/mbx_mh.c: Likewised
	* mailbox/header.c: Remove property code.
	* mailbox/body.c: Remove property code.
	* mailbox/message.c: Remove property code.
	* mailbox/filter.c: Change the code according to the new property_t.
	* mailbox/filter_rfc822.c: Change the code according to the new
	property_t.
	* include/mailutils/header.h: Remove property.
	* include/mailutils/body.h: Remove property.
	* include/mailutils/message.h: Remove property.
	* include/mailutils/property.h: Remove property_add_defaults()
	property_set_valued () takes one more argument for overwrite.
	* mailbox/include/header0.hy: Remove property field.
	* mailbox/include/body0.hy: Remove property field.
	* mailbox/include/message0.hy: Remove property field.
	* mailbox/mailbox.c(mailbox_get_property mailbox_set_property):
	Changed Property code.
	* mailbox/mailer.c(mailer_set_property mailer_get_property):
	Changed Property code.

	* mailbox/folder_imap.c (imap_search imap_expunge imap_status): Stubs
	Search is not implemented yet, STATUS neither and EXPUNGE is not used.

	* mailbox/list.c: Rename variable index to indx to shutup
	gcc whos confusing with index() when warning level was high.
	* mailbox/md5-rsa.c: Likewised.

	* mailbox/mailbox.c (mailbox_get_debug mailbox_set_debug):
	The debug object was being set on the folder not the mailbox.

	* mailbox/mbx_imap.c (imap_messages_count): Attempt to reconnect
	if the connection timeout.  Is this wise ?
	(imap_scan0): Move gut of imap_scan() code tho here.
	(imap_scan): Stub calling imap_scan0() with notification enable.
	(imap_expunge): After CLOSE, call imap_scan0() wiht notification
	disable.

	Memory leak in parse822, this was a real pain to trace, because
	of the recursive nature of the algorithm.  Sam should buy me
	a beer for this.

	* mailbox/parse822.c: Use more assert to catch errors.
	(parse822_group): phrase was not free() in case of failure.
	(parse822_mail_box): Dead if branch remove and free phrase.
	(parse822_route): accumulator was not being freed.
	(parse822_local_part): Move down st_free(more).
	(parse822_domain): Move down st_free(more).
1 parent 26132201
2001-10-14 Alain Magloire
The code for property.c has been change for a more simple approach,
it is the same approach as in mail/util.c(environment) settings.
The old code was simply overkill, property_t was seldomly use
if at all and no need for heavy hash table and all that jazz.
* mailbox/property.c: New code, the same as mail/util.c
environment.
* mailbox/mbx_mbox.c (_mbx_init): Remove property_add_defaults() etc ..
no longer in use in the initialisation code.
* mailbox/mbx_imap.c: Likewised
* mailbox/mbx_pop.c: Likewised
* mailbox/mbx_mh.c: Likewised
* mailbox/header.c: Remove property code.
* mailbox/body.c: Remove property code.
* mailbox/message.c: Remove property code.
* mailbox/filter.c: Change the code according to the new property_t.
* mailbox/filter_rfc822.c: Change the code according to the new
property_t.
* include/mailutils/header.h: Remove property.
* include/mailutils/body.h: Remove property.
* include/mailutils/message.h: Remove property.
* include/mailutils/property.h: Remove property_add_defaults()
property_set_valued () takes one more argument for overwrite.
* mailbox/include/header0.hy: Remove property field.
* mailbox/include/body0.hy: Remove property field.
* mailbox/include/message0.hy: Remove property field.
* mailbox/mailbox.c(mailbox_get_property mailbox_set_property):
Changed Property code.
* mailbox/mailer.c(mailer_set_property mailer_get_property):
Changed Property code.
* mailbox/folder_imap.c (imap_search imap_expunge imap_status): Stubs
Search is not implemented yet, STATUS neither and EXPUNGE is not used.
* mailbox/list.c: Rename variable index to indx to shutup
gcc whos confusing with index() when warning level was high.
* mailbox/md5-rsa.c: Likewised.
* mailbox/mailbox.c (mailbox_get_debug mailbox_set_debug):
The debug object was being set on the folder not the mailbox.
* mailbox/mbx_imap.c (imap_messages_count): Attempt to reconnect
if the connection timeout. Is this wise ?
(imap_scan0): Move gut of imap_scan() code tho here.
(imap_scan): Stub calling imap_scan0() with notification enable.
(imap_expunge): After CLOSE, call imap_scan0() wiht notification
disable.
Memory leak in parse822, this was a real pain to trace, because
of the recursive nature of the algorithm. Sam should buy me
a beer for this.
* mailbox/parse822.c: Use more assert to catch errors.
(parse822_group): phrase was not free() in case of failure.
(parse822_mail_box): Dead if branch remove and free phrase.
(parse822_route): accumulator was not being freed.
(parse822_local_part): Move down st_free(more).
(parse822_domain): Move down st_free(more).
2001-10-14 Sergey Poznyakoff
Small fixes:
......
......@@ -19,7 +19,6 @@
#define _MAILUTILS_BODY_H
#include <sys/types.h>
#include <mailutils/property.h>
#include <mailutils/stream.h>
#ifndef __P
......@@ -47,9 +46,6 @@ extern int body_clear_modified __P ((body_t));
extern int body_get_stream __P ((body_t, stream_t *));
extern int body_set_stream __P ((body_t, stream_t, void *owner));
extern int body_get_property __P ((body_t, property_t *));
extern int body_set_property __P ((body_t, property_t, void *));
extern int body_get_filename __P ((body_t, char *, size_t, size_t *));
extern int body_size __P ((body_t, size_t*));
......
......@@ -20,7 +20,6 @@
#include <sys/types.h>
#include <mailutils/stream.h>
#include <mailutils/property.h>
#ifndef __P
#ifdef __STDC__
......@@ -86,9 +85,6 @@ extern void *header_get_owner __P ((header_t));
extern int header_is_modified __P ((header_t));
extern int header_clear_modified __P ((header_t));
extern int header_get_property __P ((header_t, property_t *));
extern int header_set_property __P ((header_t, property_t, void *));
extern int header_set_value __P ((header_t, const char *,
const char *, int));
extern int header_set_set_value __P ((header_t,
......
......@@ -30,7 +30,6 @@ typedef struct _message *message_t;
#include <mailutils/stream.h>
#include <mailutils/observer.h>
#include <mailutils/attribute.h>
#include <mailutils/property.h>
#include <mailutils/mailbox.h>
#ifndef __P
......@@ -72,8 +71,6 @@ extern int message_set_body __P ((message_t, body_t, void *));
extern int message_get_stream __P ((message_t, stream_t *));
extern int message_set_stream __P ((message_t, stream_t, void *));
extern int message_get_property __P ((message_t, property_t *));
extern int message_set_property __P ((message_t, property_t, void *));
extern int message_get_attribute __P ((message_t, attribute_t *));
extern int message_set_attribute __P ((message_t, attribute_t, void *));
......
......@@ -35,19 +35,14 @@ extern "C" {
struct _property;
typedef struct _property *property_t;
extern int property_create __P ((property_t *, void *));
extern int property_create __P ((property_t *, void *));
extern void property_destroy __P ((property_t *, void *));
extern void *property_get_owner __P ((property_t));
extern int property_set_value __P ((property_t, const char *, const char *));
extern int property_get_value
__P ((property_t, const char *, char *, size_t, size_t *));
extern int property_add_defaults
__P ((property_t, const char *, const char *,
int (*) __P ((property_t, const char *, const char *)),
int (*) __P ((property_t, const char *, char *, size_t, size_t *)),
void *));
extern int property_set_value __P ((property_t, const char *,
const char *, int));
extern int property_get_value __P ((property_t, const char *, char *,
size_t, size_t *));
/* Helper functions. */
extern int property_set __P ((property_t, const char *));
......
......@@ -81,9 +81,6 @@ body_destroy (body_t *pbody, void *owner)
stream_destroy (&(body->fstream), NULL);
}
if (body->property)
property_destroy (&(body->property), body);
free (body);
}
*pbody = NULL;
......@@ -113,33 +110,6 @@ body_clear_modified (body_t body)
}
int
body_set_property (body_t body, property_t property, void *owner)
{
if (body == NULL)
return EINVAL;
if (body->owner != owner)
return EACCES;
property_destroy (&(body->property), body);
body->property = property;
return 0;
}
int
body_get_property (body_t body, property_t *pproperty)
{
if (body == NULL || pproperty == NULL)
return EINVAL;
if (body->property == NULL)
{
int status = property_create (&(body->property), body);
if (status != 0)
return status;
}
*pproperty = body->property;
return 0;
}
int
body_get_filename (body_t body, char *filename, size_t len, size_t *pn)
{
int n = 0;
......
......@@ -122,29 +122,6 @@ filter_close (stream_t stream)
return stream_close (filter->stream);
}
static int
filter_property (property_t property, const char *key, const char *value)
{
filter_t filter = property_get_owner (property);
(void)key;
if (value)
{
if (strcasecmp (value, "READ") == 0)
{
filter->direction = MU_STREAM_READ;
}
else if (strcasecmp (value, "WRITE") == 0)
{
filter->direction = MU_STREAM_WRITE;
}
else if (strcasecmp (value, "RDWR") == 0)
{
filter->direction = MU_STREAM_RDWR;
}
}
return 0;
}
/* NOTE: We will leak here since the monitor of the filter will never
be release. That's ok we can leave with this, it's only done once. */
static list_t filter_list;
......@@ -241,12 +218,11 @@ filter_create (stream_t *pstream, stream_t stream, const char *name,
free (filter);
return status;
}
property_add_defaults (filter->property, "DIRECTION",
((filter->direction == MU_STREAM_WRITE) ? "WRITE":
(filter->direction == MU_STREAM_RDWR) ? "RDWR" :
"READ"), filter_property, NULL, filter);
property_add_defaults (filter->property, "NAME", filter_record->name,
NULL, NULL, filter);
property_set_value (filter->property, "DIRECTION",
((filter->direction == MU_STREAM_WRITE) ? "WRITE":
(filter->direction == MU_STREAM_RDWR) ? "RDWR" :
"READ"), 1);
property_set_value (filter->property, "TYPE", filter_record->name, 1);
stream_set_property (*pstream, filter->property, filter);
if (f_init != NULL)
......
......@@ -27,7 +27,6 @@
#include <mailutils/property.h>
#include <filter0.h>
static int rfc822_property __P ((property_t, const char *, const char *));
static int rfc822_init __P ((filter_t));
static void rfc822_destroy __P ((filter_t));
static int rfc822_read __P ((filter_t, char *, size_t, off_t, size_t *));
......@@ -55,16 +54,6 @@ static struct _filter_record _rfc822_filter =
filter_record_t rfc822_filter = &_rfc822_filter;
static int
rfc822_property (property_t property, const char *key, const char *value)
{
filter_t filter = property_get_owner (property);
struct rfc822 *rfc822 = filter->data;
(void)key;
rfc822->lines = strtoul (value, NULL, 10);
return 0;
}
static int
rfc822_init (filter_t filter)
{
property_t property;
......@@ -79,8 +68,7 @@ rfc822_init (filter_t filter)
/* We are interested in this property. */
if ((status = stream_get_property (filter->filter_stream, &property) != 0)
|| (status = property_add_defaults (property, "LINES", "0",
rfc822_property, NULL, filter)) != 0)
|| (status = property_set_value (property, "LINES", "0", 1)) != 0)
{
free (filter->data);
filter->data = NULL;
......
......@@ -59,43 +59,46 @@ static struct _record _imap_record =
record_t imap_record = &_imap_record;
#ifndef HAVE_STRTOK_R
char *strtok_r __P ((char *, const char *, char **));
char *strtok_r __P ((char *, const char *, char **));
#endif
/* Concrete IMAP implementation. */
static int folder_imap_open __P ((folder_t, int));
static int folder_imap_create __P ((folder_t));
static int folder_imap_close __P ((folder_t));
static void folder_imap_destroy __P ((folder_t));
static int folder_imap_delete __P ((folder_t, const char *));
static int folder_imap_list __P ((folder_t, const char *, const char *,
struct folder_list *));
static int folder_imap_lsub __P ((folder_t, const char *, const char *,
struct folder_list *));
static int folder_imap_rename __P ((folder_t, const char *,
const char *));
static int folder_imap_subscribe __P ((folder_t, const char *));
static int folder_imap_unsubscribe __P ((folder_t, const char *));
/* Private */
/* static int imap_readline (f_imap_t); */
/* Concrete folder_t IMAP implementation. */
static int folder_imap_open __P ((folder_t, int));
static int folder_imap_create __P ((folder_t));
static int folder_imap_close __P ((folder_t));
static void folder_imap_destroy __P ((folder_t));
static int folder_imap_delete __P ((folder_t, const char *));
static int folder_imap_list __P ((folder_t, const char *, const char *,
struct folder_list *));
static int folder_imap_lsub __P ((folder_t, const char *, const char *,
struct folder_list *));
static int folder_imap_rename __P ((folder_t, const char *,
const char *));
static int folder_imap_subscribe __P ((folder_t, const char *));
static int folder_imap_unsubscribe __P ((folder_t, const char *));
/* FETCH */
static int imap_fetch __P ((f_imap_t));
static int imap_rfc822 __P ((f_imap_t, char **));
static int imap_rfc822_size __P ((f_imap_t, char **));
static int imap_rfc822_header __P ((f_imap_t, char **));
static int imap_rfc822_text __P ((f_imap_t, char **));
static int imap_flags __P ((f_imap_t, char **));
static int imap_bodystructure __P ((f_imap_t, char **));
static int imap_body __P ((f_imap_t, char **));
static int imap_uid __P ((f_imap_t, char **));
static int imap_fetch __P ((f_imap_t));
static int imap_rfc822 __P ((f_imap_t, char **));
static int imap_rfc822_size __P ((f_imap_t, char **));
static int imap_rfc822_header __P ((f_imap_t, char **));
static int imap_rfc822_text __P ((f_imap_t, char **));
static int imap_flags __P ((f_imap_t, char **));
static int imap_bodystructure __P ((f_imap_t, char **));
static int imap_body __P ((f_imap_t, char **));
static int imap_internaldate __P ((f_imap_t, char **));
static int imap_uid __P ((f_imap_t, char **));
static int imap_status __P ((f_imap_t));
static int imap_expunge __P ((f_imap_t, unsigned int));
static int imap_search __P ((f_imap_t));
/* String. */
static int imap_literal_string __P ((f_imap_t, char **));
static int imap_string __P ((f_imap_t, char **));
static int imap_quoted_string __P ((f_imap_t, char **));
static int imap_literal_string __P ((f_imap_t, char **));
static int imap_string __P ((f_imap_t, char **));
static int imap_quoted_string __P ((f_imap_t, char **));
static int imap_token __P ((char *, size_t, char **));
static int imap_token __P ((char *, size_t, char **));
/* Initialize the concrete IMAP mailbox: overload the folder functions */
int
......@@ -486,7 +489,7 @@ folder_imap_delete (folder_t folder, const char *name)
return status;
}
/* Since the mailutils API does not offer recursive listing. There is no need
/* Since mailutils API does not offer recursive listing. There is no need
to follow IMAP "bizarre" recursive rules. The use of '%' is sufficient. So
the approach is everywhere there is a regex in the path we change that
branch for '%' and do the matching ourself with fnmatch(). */
......@@ -810,8 +813,6 @@ folder_imap_unsubscribe (folder_t folder, const char *name)
return status;
}
/* Implementation. */
/* A literal is a sequence of zero or more octets (including CR and LF),
prefix-quoted with an octet count in the form of an open brace ("{"),
the number of octets, close brace ("}"), and CRLF. The sequence is read
......@@ -1563,6 +1564,32 @@ imap_fetch (f_imap_t f_imap)
}
static int
imap_search (f_imap_t f_imap)
{
(void)f_imap;
/* Not implemented. No provision for this in the API, yet. */
return 0;
}
static int
imap_status (f_imap_t f_imap)
{
(void)f_imap;
/* Not implemented. No provision for this in the API, yet. */
return 0;
}
static int
imap_expunge (f_imap_t f_imap, unsigned msgno)
{
(void)f_imap; (void)msgno;
/* We should not have this, since do not send the expunge, but rather
use SELECT/CLOSE. */
return 0;
}
static int
imap_token (char *buf, size_t len, char **ptr)
{
char *start = *ptr;
......@@ -1973,6 +2000,8 @@ imap_parse (f_imap_t f_imap)
}
else if (strcasecmp (remainder, "EXPUNGE") == 0)
{
unsigned int msgno = strtol (response, NULL, 10);
status = imap_expunge (f_imap, msgno);
}
else if (strncasecmp (remainder, "FETCH", 5) == 0)
{
......@@ -1999,9 +2028,11 @@ imap_parse (f_imap_t f_imap)
}
else if (strcasecmp (response, "SEARCH") == 0)
{
status = imap_search (f_imap);
}
else if (strcasecmp (response, "STATUS") == 0)
{
status = imap_status (f_imap);
}
else
{
......@@ -2021,6 +2052,7 @@ imap_parse (f_imap_t f_imap)
done = 1;
if (strcasecmp (response, "OK") == 0)
{
/* Cool we are doing ok. */
}
else /* NO and BAD */
{
......
......@@ -100,9 +100,6 @@ header_destroy (header_t *ph, void *owner)
header_free_cache (header);
if (header->property)
property_destroy (&(header->property), header);
free (header);
}
*ph = NULL;
......@@ -781,33 +778,6 @@ header_size (header_t header, size_t *psize)
}
int
header_set_property (header_t header, property_t property, void *owner)
{
if (header == NULL)
return EINVAL;
if (header->owner != owner)
return EACCES;
property_destroy (&(header->property), header);
header->property = property;
return 0;
}
int
header_get_property (header_t header, property_t *pp)
{
if (header == NULL || pp == NULL)
return EINVAL;
if (header->property == NULL)
{
int status = property_create (&(header->property), header);
if (status != 0)
return status;
}
*pp = header->property;
return 0;
}
int
header_set_get_fvalue (header_t header, int (*_get_fvalue)
__P ((header_t, const char *, char *, size_t,
size_t *)), void *owner)
......
......@@ -46,7 +46,6 @@ struct _body
char *filename;
stream_t stream;
stream_t fstream;
property_t property;
int flags;
int (*_size) (body_t, size_t*);
......
......@@ -64,7 +64,6 @@ struct _header
size_t fhdr_count;
struct _hdr *fhdr;
int flags;
property_t property;
/* Streams. */
stream_t stream;
......
......@@ -40,14 +40,6 @@ extern "C" {
# endif
#endif /*__P */
struct default_properties
{
char *key;
char *value;
int (*_set_value) __P ((property_t, const char *, const char *));
int (*_get_value) __P ((property_t, const char *, char *, size_t, size_t *));
};
struct _mailbox
{
/* Data */
......@@ -56,8 +48,6 @@ struct _mailbox
ticket_t ticket;
authority_t authority;
property_t property;
struct default_properties *properties;
size_t properties_count;
locker_t locker;
stream_t stream;
url_t url;
......@@ -72,25 +62,25 @@ struct _mailbox
void (*_destroy) __P ((mailbox_t));
int (*_open) __P ((mailbox_t, int flag));
int (*_open) __P ((mailbox_t, int));
int (*_close) __P ((mailbox_t));
/* messages */
int (*_get_message) __P ((mailbox_t, size_t msgno, message_t *msg));
int (*_append_message) __P ((mailbox_t, message_t msg));
int (*_messages_count) __P ((mailbox_t, size_t *num));
int (*_messages_recent) __P ((mailbox_t, size_t *num));
int (*_message_unseen) __P ((mailbox_t, size_t *num));
int (*_get_message) __P ((mailbox_t, size_t, 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 (*_message_unseen) __P ((mailbox_t, size_t *));
int (*_expunge) __P ((mailbox_t));
int (*_save_attributes) __P ((mailbox_t));
int (*_uidvalidity) __P ((mailbox_t, unsigned long *num));
int (*_uidnext) __P ((mailbox_t, size_t *num));
int (*_get_property) __P ((mailbox_t, property_t *num));
int (*_uidvalidity) __P ((mailbox_t, unsigned long *));
int (*_uidnext) __P ((mailbox_t, size_t *));
int (*_get_property) __P ((mailbox_t, property_t *));
int (*_scan) __P ((mailbox_t, size_t msgno, size_t *count));
int (*_scan) __P ((mailbox_t, size_t, size_t *));
int (*_is_updated) __P ((mailbox_t));
int (*_get_size) __P ((mailbox_t, off_t *size));
int (*_get_size) __P ((mailbox_t, off_t *));
};
......
......@@ -53,14 +53,6 @@ extern "C" {
#define MAILER_LINE_BUF_SIZE 1000
struct default_properties
{
char *key;
char *value;
int (*_set_value) __P ((property_t, const char *, const char *));
int (*_get_value) __P ((property_t, const char *, char *, size_t, size_t *));
};
struct _mailer
{
stream_t stream;
......@@ -70,7 +62,6 @@ struct _mailer
int flags;
monitor_t monitor;
property_t property;
struct default_properties *properties;
size_t properties_count;
/* Pointer to the specific mailer data. */
......
......@@ -52,7 +52,6 @@ struct _message
int flags;
stream_t stream;
property_t property;
attribute_t attribute;
monitor_t monitor;
mime_t mime;
......
......@@ -27,7 +27,7 @@
#include <string.h>
#include <mailutils/property.h>
#include <mailutils/iterator.h>
#include <mailutils/monitor.h>
#ifndef __P
#ifdef __STDC__
......@@ -41,19 +41,19 @@
extern "C" {
#endif
struct property_data
struct property_item
{
size_t hash;
char *key;
char *value;
int (*_set_value) __P ((property_t, const char *, const char *));
int (*_get_value) __P ((property_t, const char *, char *, size_t, size_t *));
int set;
struct property_item *next;
};
struct _property
{
struct property_item *items;
void *owner;
list_t list;
monitor_t lock;
};
#ifdef __cplusplus
......
......@@ -158,7 +158,7 @@ list_remove (list_t list, void *item)
Every time we iterate through the loop to get the data, an easy
fix is to a an index to the current. */
int
list_get (list_t list, size_t index, void **pitem)
list_get (list_t list, size_t indx, void **pitem)
{
struct list_data *current;
size_t count;
......@@ -169,7 +169,7 @@ list_get (list_t list, size_t index, void **pitem)
for (current = list->head.next, count = 0; current != &(list->head);
current = current->next, count++)
{
if (count == index)
if (count == indx)
{
*pitem = current->item;
status = 0;
......
......@@ -169,17 +169,6 @@ mailbox_destroy (mailbox_t *pmbox)
if (mbox->folder)
folder_destroy (&(mbox->folder));
if (mbox->properties)
{
size_t i;
for (i = 0; i < mbox->properties_count; i++)
{
if (mbox->properties[i].key)
free (mbox->properties[i].key);
}
free (mbox->properties);
}
if (mbox->property)
property_destroy (&(mbox->property), mbox);
......@@ -427,25 +416,9 @@ mailbox_get_property (mailbox_t mbox, property_t *pproperty)
return EINVAL;
if (mbox->property == NULL)
{
size_t i;
int status = property_create (&(mbox->property), mbox);
if (status != 0)
return status;
/* Add the defaults. */
for (i = 0; i < mbox->properties_count; i++)
{
status = property_add_defaults (mbox->property,
mbox->properties[i].key,
mbox->properties[i].value,
mbox->properties[i]._set_value,
mbox->properties[i]._get_value,
mbox);
if (status != 0)
{
property_destroy (&(mbox->property), mbox);
return status;
}
}
}
*pproperty = mbox->property;
return 0;
......@@ -456,14 +429,8 @@ mailbox_set_debug (mailbox_t mbox, mu_debug_t debug)
{
if (mbox == NULL)
return EINVAL;
if (mbox->folder)
{
int status = folder_set_debug (mbox->folder, debug);
if (status)
return status;
}
if (mbox->debug)
mu_debug_destroy (&(mbox->debug), mbox);
mu_debug_destroy (&mbox->debug, mbox);
mbox->debug = debug;
return 0;
}
......@@ -473,17 +440,6 @@ mailbox_get_debug (mailbox_t mbox, mu_debug_t *pdebug)
{
if (mbox == NULL || pdebug == NULL)
return EINVAL;
if (mbox->folder)
{
int status = folder_get_debug (mbox->folder, pdebug);
if (status == 0)
{
if (mbox->debug)
mu_debug_destroy (&(mbox->debug), mbox);
mbox->debug = *pdebug;
}
return status;
}
if (mbox->debug == NULL)
{
int status = mu_debug_create (&(mbox->debug), mbox);
......
......@@ -138,19 +138,6 @@ mailer_destroy (mailer_t *pmailer)
if (mailer->debug)
mu_debug_destroy (&(mailer->debug), mailer);
if (mailer->properties)
{
size_t i;
for (i = 0; i < mailer->properties_count; i++)
{
if (mailer->properties[i].key)
free (mailer->properties[i].key);
if (mailer->properties[i].value)
free (mailer->properties[i].value);
}
free (mailer->properties);
}
if (mailer->property)
property_destroy (&(mailer->property), mailer);
......@@ -232,25 +219,9 @@ mailer_get_property (mailer_t mailer, property_t *pproperty)
return EINVAL;
if (mailer->property == NULL)
{
size_t i;
int status = property_create (&(mailer->property), mailer);
if (status != 0)
return status;
/* Add the defaults. */
for (i = 0; i < mailer->properties_count; i++)
{
status = property_add_defaults (mailer->property,
mailer->properties[i].key,
mailer->properties[i].value,
mailer->properties[i]._set_value,
mailer->properties[i]._get_value,
mailer);
if (status != 0)
{
property_destroy (&(mailer->property), mailer);
return status;
}
}
}
*pproperty = mailer->property;
return 0;
......
......@@ -51,6 +51,7 @@ static int imap_messages_count __P ((mailbox_t, size_t *));
static int imap_messages_recent __P ((mailbox_t, size_t *));
static int imap_message_unseen __P ((mailbox_t, size_t *));
static int imap_scan __P ((mailbox_t, size_t, size_t *));
static int imap_scan0 __P ((mailbox_t, size_t, size_t *, int));
static int imap_is_updated __P ((mailbox_t));
static int imap_append_message __P ((mailbox_t, message_t));
static int imap_copy_message __P ((mailbox_t, message_t));
......@@ -148,12 +149,11 @@ _mailbox_imap_init (mailbox_t mailbox)
m_imap->mailbox = mailbox;
/* Set our properties. */
mailbox->properties = calloc (1, sizeof (*(mailbox->properties)));
if (mailbox->properties == NULL)
return ENOMEM;
mailbox->properties_count = 1;
mailbox->properties[0].key = strdup ("TYPE");
mailbox->properties[0].value = strdup ("IMAP");
{
property_t property = NULL;
mailbox_get_property (mailbox, &property);
property_set_value (property, "TYPE", "IMAP4", 1);
}
return 0;
}
......@@ -218,11 +218,13 @@ mailbox_imap_destroy (mailbox_t mailbox)
static int
mailbox_imap_open (mailbox_t mailbox, int flags)
{
mailbox->flags = flags;
return folder_open (mailbox->folder, flags);
}
/* We can not close the folder in term of shuting down the connection but if
we were the selected mailbox we send the close and deselect ourself. */
we were the selected mailbox we send the close and deselect ourself.
The CLOSE is also use to expunge instead of sending expunge. */
static int
mailbox_imap_close (mailbox_t mailbox)
{
......@@ -501,6 +503,16 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum)
f_imap_t f_imap = m_imap->f_imap;
int status = 0;
/* FIXME: It is debatable if we should reconnect when the connection
timeout or die. For timeout client should ping i.e. send
a NOOP via imap_is_updated() function to keep the connection alive. */
if (!f_imap->isopen)
{
status = folder_open (mailbox->folder, mailbox->flags);
if (status != 0)
return status;
}
/* Are we already selected ? */
if (m_imap == (f_imap->selected))
{
......@@ -544,6 +556,12 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum)
return status;
}
static int
imap_scan (mailbox_t mailbox, size_t msgno, size_t *pcount)
{
return imap_scan0 (mailbox, msgno, pcount , 1);
}
/* Usually when this function is call it is because there is an oberver
attach an the client is try to build some sort of list/tree header
as the scanning progress. But doing this for each message can be
......@@ -553,7 +571,7 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum)
transcation but rather a big one. The bad thing is that every thing
will be cache in the structure using a lot of memory. */
static int
imap_scan (mailbox_t mailbox, size_t msgno, size_t *pcount)
imap_scan0 (mailbox_t mailbox, size_t msgno, size_t *pcount, int notif)
{
int status;
size_t i;
......@@ -596,11 +614,15 @@ imap_scan (mailbox_t mailbox, size_t msgno, size_t *pcount)
f_imap->state = IMAP_NO_STATE;
/* Do not send notifications. */
if (!notif)
return 0;
/* If no callbacks bail out early. */
if (mailbox->observable == NULL)
return 0;
for (i = msgno; i <= *pcount; i++)
for (i = msgno; i <= count; i++)
{
if (observable_notify (mailbox->observable, MU_EVT_MESSAGE_ADD) != 0)
break;
......@@ -704,14 +726,24 @@ imap_expunge (mailbox_t mailbox)
MAILBOX_DEBUG0 (m_imap->mailbox, MU_DEBUG_PROT, f_imap->buffer);
f_imap->state = IMAP_NO_STATE;
/* We are not sending EXPUNGE, rather we close the mailbox
which will purge. */
case IMAP_CLOSE:
case IMAP_CLOSE_ACK:
status = mailbox_imap_close (mailbox);
CHECK_EAGAIN (f_imap, status);
/* Rescan after expunging but do not trigger the observers. */
case IMAP_SCAN:
case IMAP_SCAN_ACK:
status = imap_scan0 (mailbox, 1, NULL, 0);
CHECK_EAGAIN (f_imap, status);
default:
/* mu_error ("imap_expunge: unknow state\n"); */
break;
}
/* Tell the server to delete the messages but without sending the
EXPUNGE response. We can do the calculations. */
status = mailbox_imap_close (mailbox);
return status;
}
......
......@@ -278,12 +278,11 @@ _mailbox_mbox_init (mailbox_t mailbox)
mailbox->_get_size = mbox_get_size;
/* Set our properties. */
mailbox->properties = calloc (1, sizeof (*(mailbox->properties)));
if (mailbox->properties == NULL)
return ENOMEM;
mailbox->properties_count = 1;
mailbox->properties[0].key = strdup ("TYPE");
mailbox->properties[0].value = strdup ("MBOX");
{
property_t property = NULL;
mailbox_get_property (mailbox, &property);
property_set_value (property, "TYPE", "MBOX", 1);
}
MAILBOX_DEBUG1 (mailbox, MU_DEBUG_TRACE, "mbox_init(%s)\n", mud->name);
return 0; /* okdoke */
......
......@@ -217,12 +217,11 @@ _mailbox_mh_init (mailbox_t mailbox)
mailbox->_get_size = mh_get_size;
/* Set our properties. */
mailbox->properties = calloc (1, sizeof (*mailbox->properties));
if (mailbox->properties == NULL)
return ENOMEM;
mailbox->properties_count = 1;
mailbox->properties[0].key = strdup ("TYPE");
mailbox->properties[0].value = strdup ("MH");
{
property_t property = NULL;
mailbox_get_property (mailbox, &property);
property_set_value (property, "TYPE", "MH", 1);
}
MAILBOX_DEBUG1 (mailbox, MU_DEBUG_TRACE, "mh_init(%s)\n", mhd->name);
return 0;
......
......@@ -353,38 +353,16 @@ _mailbox_pop_init (mailbox_t mbox)
mbox->_get_size = pop_get_size;
/* Properties. */
mbox->properties = calloc (1, sizeof (*(mbox->properties)));
if (mbox->properties == NULL)
{
status = ENOMEM;
goto END;
}
mbox->properties_count = 1;
mbox->properties[0].key = strdup ("TYPE");
mbox->properties[0].value = strdup ("POP3");
if (mbox->properties[0].key == NULL || mbox->properties[0].value == NULL)
{
status = ENOMEM;
goto END;
}
/* Set our properties. */
{
property_t property = NULL;
mailbox_get_property (mbox, &property);
property_set_value (property, "TYPE", "POP3", 1);
}
/* Hack! */
/* Hack! POP does not really have a folder. */
mbox->folder->data = mbox;
END:
if (status != 0)
{
if (mbox->properties[0].key)
free (mbox->properties[0].key);
if (mbox->properties[0].value)
free (mbox->properties[0].value);
if (mbox->properties)
free (mbox->properties);
if (mbox->data)
free (mbox->data);
}
return status;
}
......
......@@ -117,10 +117,10 @@ MD5_CTX *context; /* context */
unsigned char *input; /* input block */
unsigned int inputLen; /* length of input block */
{
unsigned int i, index, partLen;
unsigned int i, indx, partLen;
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
indx = (unsigned int)((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
if ((context->count[0] += ((UINT4)inputLen << 3))
......@@ -128,26 +128,26 @@ unsigned int inputLen; /* length of input block */
context->count[1]++;
context->count[1] += ((UINT4)inputLen >> 29);
partLen = 64 - index;
partLen = 64 - indx;
/* Transform as many times as possible.
*/
if (inputLen >= partLen) {
MD5_memcpy
((POINTER)&context->buffer[index], (POINTER)input, partLen);
((POINTER)&context->buffer[indx], (POINTER)input, partLen);
MD5Transform (context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64)
MD5Transform (context->state, &input[i]);
index = 0;
indx = 0;
}
else
i = 0;
/* Buffer remaining input */
MD5_memcpy
((POINTER)&context->buffer[index], (POINTER)&input[i],
((POINTER)&context->buffer[indx], (POINTER)&input[i],
inputLen-i);
}
......@@ -159,15 +159,15 @@ unsigned char digest[16]; /* message digest */
MD5_CTX *context; /* context */
{
unsigned char bits[8];
unsigned int index, padLen;
unsigned int indx, padLen;
/* Save number of bits */
Encode (bits, context->count, 8);
/* Pad out to 56 mod 64.
*/
index = (unsigned int)((context->count[0] >> 3) & 0x3f);
padLen = (index < 56) ? (56 - index) : (120 - index);
indx = (unsigned int)((context->count[0] >> 3) & 0x3f);
padLen = (indx < 56) ? (56 - indx) : (120 - indx);
MD5Update (context, PADDING, padLen);
/* Append length (before padding) */
......
......@@ -185,37 +185,6 @@ message_clear_modified (message_t msg)
}
int
message_set_property (message_t msg, property_t property, void *owner)
{
if (msg == NULL)
return EINVAL;
if (msg->owner != owner)
return EACCES;
header_set_property (msg->header, property, msg);
body_set_property (msg->body, property, msg);
property_destroy (&(msg->property), msg);
msg->property = property;
return 0;
}
int
message_get_property (message_t msg, property_t *pproperty)
{
if (msg == NULL || pproperty == NULL)
return EINVAL;
if (msg->property == NULL)
{
int status = property_create (&(msg->property), msg);
if (status != 0)
return status;
header_set_property (msg->header, msg->property, msg);
body_set_property (msg->body, msg->property, msg);
}
*pproperty = msg->property;
return 0;
}
int
message_get_mailbox (message_t msg, mailbox_t *pmailbox)
{
if (msg == NULL || pmailbox == NULL)
......
......@@ -508,6 +508,7 @@ int parse822_word(const char** p, const char* e, char** word)
return rc;
}
assert(qstr == NULL);
}
if(rc != EPARSE) {
......@@ -532,6 +533,7 @@ int parse822_word(const char** p, const char* e, char** word)
return rc;
}
assert (atom == NULL);
}
return EPARSE;
......@@ -562,6 +564,7 @@ int parse822_phrase(const char** p, const char* e, char** phrase)
if(rc != EOK)
break;
}
assert(word == NULL);
if(rc == EPARSE)
rc = EOK; /* its not an error to find no more words */
}
......@@ -713,6 +716,7 @@ int parse822_group(const char** p, const char* e, address_t* a)
if((rc = parse822_special(p, e, ':'))) {
*p = save;
str_free(&phrase);
return rc;
}
......@@ -807,12 +811,9 @@ int parse822_mail_box(const char** p, const char* e, address_t* a)
(*a)->personal = phrase;
return EOK;
} else if(rc != EPARSE) {
/* some internal error, fail out */
*p = save;
str_free(&phrase);
return rc;
}
/* some internal error, fail out */
str_free(&phrase);
*p = save;
return rc;
......@@ -910,10 +911,9 @@ int parse822_route(const char** p, const char* e, char** route)
rc = str_append(route, accumulator);
}
if(rc) {
str_free(&accumulator);
*p = save;
}
str_free(&accumulator);
return rc;
}
......@@ -1008,8 +1008,8 @@ int parse822_local_part(const char** p, const char* e, char** local_part)
if((rc = str_append(local_part, ".")) == EOK) {
rc = str_append(local_part, more);
}
str_free(&more);
}
str_free(&more);
}
if(rc == EPARSE) {
......@@ -1062,8 +1062,8 @@ int parse822_domain(const char** p, const char* e, char** domain)
if((rc = str_append(domain, ".")) == EOK) {
rc = str_append(domain, more);
}
str_free(&more);
}
str_free(&more);
}
if(rc == EPARSE) {
/* we didn't parse more ("." sub-domain) pairs, that's ok */
......
......@@ -24,14 +24,11 @@
#include <property0.h>
static int property_find __P ((list_t, const char *, struct property_data **));
static int property_add __P ((property_t, const char *, const char *,
int (*_set_value)
__P ((property_t, const char *, const char *)),
int (*_get_value)
__P ((property_t, const char *, char *,
size_t, size_t *))));
static size_t property_hash __P ((const char *));
#undef min
#define min(a,b) ((a) < (b) ? (a) : (b))
static int property_find __P ((property_t, const char *,
struct property_item **));
int
property_create (property_t *pp, void *owner)
......@@ -39,9 +36,10 @@ property_create (property_t *pp, void *owner)
property_t prop;
if (pp == NULL)
return EINVAL;
prop = calloc (1, sizeof (*prop));
prop = calloc (1, sizeof *prop);
if (prop == NULL)
return ENOMEM;
monitor_create (&prop->lock, 0, prop);
prop->owner = owner;
*pp = prop;
return 0;
......@@ -55,29 +53,20 @@ property_destroy (property_t *pp, void *owner)
property_t prop = *pp;
if (prop->owner == owner)
{
struct property_item *item, *cur;
/* Destroy the list and is properties. */
if (prop->list)
monitor_wrlock (prop->lock);
for (item = prop->items; item; item = cur)
{
struct property_data *pd = NULL;
iterator_t iterator = NULL;
iterator_create (&iterator, prop->list);
for (iterator_first (iterator); !iterator_is_done (iterator);
iterator_next (iterator))
{
iterator_current (iterator, (void **)&pd);
if (pd)
{
if (pd->key)
free (pd->key);
if (pd->value)
free (pd->value);
free (pd);
}
}
iterator_destroy (&iterator);
list_destroy (&(prop->list));
if (item->key)
free (item->key);
if (item->value)
free (item->value);
cur = item->next;
free (item);
}
monitor_unlock (prop->lock);
monitor_destroy (&prop->lock, prop);
free (prop);
}
*pp = NULL;
......@@ -91,214 +80,137 @@ property_get_owner (property_t prop)
}
int
property_add_defaults (property_t prop, const char *key, const char *value,
int (*_set_value) __P ((property_t, const char *,
const char *)),
int (*_get_value) __P ((property_t, const char *,
char *, size_t, size_t *)),
void *owner)
{
if (prop == NULL)
return EINVAL;
if (prop->owner != owner)
return EACCES;
return property_add (prop, key, value, _set_value, _get_value);
}
int
property_set_value (property_t prop, const char *key, const char *value)
property_set_value (property_t prop, const char *key, const char *value,
int overwrite)
{
struct property_item *item;
int status = property_find (prop, key, &item);
if (status != 0)
return status;
if (prop == NULL)
return EINVAL;
return property_add (prop, key, value, NULL, NULL);
if (item->set)
{
if (overwrite)
{
item->set = 0;
if (item->value)
free (item->value);
item->value = NULL;
if (value)
{
item->set = 1;
item->value = strdup (value);
if (item->value == NULL)
status = ENOMEM;
}
}
}
else
{
item->set = 1;
if (item->value)
free (item->value);
if (value)
{
item->value = strdup (value);
if (item->value == NULL)
status = ENOMEM;
}
}
return status;
}
int
property_get_value (property_t prop, const char *key, char *buffer,
size_t buflen, size_t *n)
{
struct property_data *pd = NULL;
struct property_item *item = NULL;
int status;
size_t len;
if (prop == NULL)
return EINVAL;
status = property_find (prop->list, key, &pd);
status = property_find (prop, key, &item);
if (status != 0)
return status;
if (pd == NULL)
return ENOENT;
if (pd->_get_value)
return pd->_get_value (prop, key, buffer, buflen, n);
len = (pd->value) ? strlen (pd->value) : 0;
len = (item->value) ? strlen (item->value) : 0;
if (buffer && buflen != 0)
{
buflen--;
len = (buflen < len) ? buflen : len;
strncpy (buffer, pd->value, len)[len] = '\0';
len = min (buflen, len);
strncpy (buffer, item->value, len)[len] = '\0';
}
if (n)
*n = len;
return 0;
}
#if 0
int
property_load (property_t prop, stream_t stream)
{
size_t n = 0;
off_t off = 0;
int status;
int buflen = 512;
char *buf = calloc (buflen, sizeof (*buf));
if (buf == NULL)
return ENOMEM;
while ((status = stream_readline (stream, buf, buflen, off, &n)) == 0
&& n > 0)
{
char *sep;
if (buf[n] != '\n')
{
char *tmp;
buflen *= 2;
tmp = realloc (buf, buflen);
if (tmp == NULL)
{
free (buf);
return ENOMEM;
}
buf = tmp;
continue;
}
sep = strchr (buf, '=');
if (sep)
{
*sep++ = '\0';
property_set_value (prop, buf, sep);
}
else
property_set (prop, buf);
}
return 0;
}
#endif
int
property_set (property_t prop, const char *k)
{
if (!property_is_set (prop, k))
return property_set_value (prop, k, "1");
struct property_item *item = NULL;
int status = property_find (prop, k, &item);
if (status != 0)
return status;
item->set = 1;
return 0;
}
int
property_unset (property_t prop, const char *k)
{
if (property_is_set (prop, k))
return property_set_value (prop, k, NULL);
struct property_item *item = NULL;
int status = property_find (prop, k, &item);
if (status != 0)
return status;
item->set = 0;
return 0;
}
int
property_is_set (property_t prop, const char *k)
{
size_t n = 0;
property_get_value (prop, k, NULL, 0, &n);
return (n != 0);
}
/* Taking from an article in Dr Dobbs. */
static size_t
property_hash (const char *s)
{
size_t hashval;
for (hashval = 0; *s != '\0' ; s++)
{
hashval += (unsigned)*s ;
hashval += (hashval << 10);
hashval ^= (hashval >> 6) ;
}
hashval += (hashval << 3);
hashval ^= (hashval >> 11);
hashval += (hashval << 15);
return hashval;
}
static int
property_find (list_t list, const char *key, struct property_data **p)
{
int status;
size_t h;
struct property_data *pd = NULL;
iterator_t iterator;
status = iterator_create (&iterator, list);
struct property_item *item = NULL;
int status = property_find (prop, k, &item);
if (status != 0)
return status;
h = property_hash (key);
for (iterator_first (iterator); !iterator_is_done (iterator);
iterator_next (iterator))
{
iterator_current (iterator, (void **)&pd);
if (pd)
{
if (pd->hash == h)
if (pd->key && strcasecmp (pd->key, key) == 0)
break;
}
pd = NULL;
}
iterator_destroy (&iterator);
*p = pd;
return 0;
return 0;
return item->set;
}
static int
property_add (property_t prop, const char *key, const char *value,
int (*_set_value) __P ((property_t, const char *, const char *)),
int (*_get_value) __P ((property_t, const char *, char *,
size_t, size_t *)))
property_find (property_t prop, const char *key, struct property_item **item)
{
struct property_data *pd = NULL;
int status;
size_t len = 0;
struct property_item *cur = NULL;
if (key == NULL || *key == '\0')
if (prop == NULL || key == NULL)
return EINVAL;
if (prop->list == NULL)
monitor_wrlock (prop->lock);
for (len = strlen (key), cur = prop->items; cur; cur = cur->next)
{
status = list_create (&(prop->list));
if (status != 0)
return status;
if (strlen (cur->key) == len && !strcmp (key, cur->key))
break;
}
status = property_find (prop->list, key, &pd);
if (status != 0)
return status;
/* None find create a new one. */
if (pd == NULL)
if (cur == NULL)
{
pd = calloc (1, sizeof (*pd));
if (pd == NULL)
return ENOMEM;
pd->hash = property_hash (key);
list_append (prop->list, (void *)pd);
cur = calloc (1, sizeof *cur);
if (cur == NULL)
{
monitor_unlock (prop->lock);
return ENOMEM;
}
cur->key = strdup (key);
if (cur->key == NULL)
{
monitor_unlock (prop->lock);
free (cur);
return ENOMEM;
}
cur->next = prop->items;
prop->items = cur;
}
if (pd->key == NULL)
pd->key = strdup (key);
if (pd->value)
free (pd->value);
pd->value = (value) ? strdup (value) : NULL;
pd->_set_value = _set_value;
pd->_get_value = _get_value;
*item = cur;
monitor_unlock (prop->lock);
return 0;
}
......
......@@ -82,12 +82,11 @@ _mailer_sendmail_init (mailer_t mailer)
mailer->_send_message = sendmail_send_message;
/* Set our properties. */
mailer->properties = calloc (1, sizeof (*(mailer->properties)));
if (mailer->properties == NULL)
return ENOMEM;
mailer->properties_count = 1;
mailer->properties[0].key = strdup ("TYPE");
mailer->properties[0].value = strdup ("SENDMAIL");
{
property_t property = NULL;
mailer_get_property (mailer, &property);
property_set_value (property, "TYPE", "SENDMAIL", 1);
}
return 0;
}
......
......@@ -161,12 +161,11 @@ _mailer_smtp_init (mailer_t mailer)
mailer->_send_message = smtp_send_message;
/* Set our properties. */
mailer->properties = calloc (1, sizeof (*(mailer->properties)));
if (mailer->properties == NULL)
return ENOMEM;
mailer->properties_count = 1;
mailer->properties[0].key = strdup ("TYPE");
mailer->properties[0].value = strdup ("SMTP");
{
property_t property = NULL;
mailer_get_property (mailer, &property);
property_set_value (property, "TYPE", "SMTP", 1);
}
return 0;
}
......