A little cleanup and we prepare support for IMAP.
Showing
44 changed files
with
756 additions
and
88 deletions
... | @@ -40,6 +40,7 @@ extern int ticket_create __P ((ticket_t *, void *owner)); | ... | @@ -40,6 +40,7 @@ extern int ticket_create __P ((ticket_t *, void *owner)); |
40 | extern void ticket_destroy __P ((ticket_t *, void *owner)); | 40 | extern void ticket_destroy __P ((ticket_t *, void *owner)); |
41 | extern void * ticket_get_owner __P ((ticket_t)); | 41 | extern void * ticket_get_owner __P ((ticket_t)); |
42 | 42 | ||
43 | extern int ticket_set_pop __P ((ticket_t, int (*_pop) __P ((ticket_t, const char *, char **)), void *)); | ||
43 | extern int ticket_pop __P ((ticket_t, const char *, char **)); | 44 | extern int ticket_pop __P ((ticket_t, const char *, char **)); |
44 | 45 | ||
45 | extern int ticket_get_type __P ((ticket_t, char *, size_t, size_t *)); | 46 | extern int ticket_get_type __P ((ticket_t, char *, size_t, size_t *)); | ... | ... |
include/mailutils/folder.h
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #ifndef _MAILUTILS_FOLDER_H | ||
19 | # define _MAILUTILS_FOLDER_H | ||
20 | |||
21 | #include <sys/types.h> | ||
22 | |||
23 | #include <mailutils/url.h> | ||
24 | #include <mailutils/observer.h> | ||
25 | #include <mailutils/debug.h> | ||
26 | #include <mailutils/list.h> | ||
27 | #include <mailutils/auth.h> | ||
28 | #include <mailutils/stream.h> | ||
29 | |||
30 | |||
31 | #ifdef __cplusplus | ||
32 | extern "C" { | ||
33 | #endif | ||
34 | |||
35 | #ifndef __P | ||
36 | # ifdef __STDC__ | ||
37 | # define __P(args) args | ||
38 | # else | ||
39 | # define __P(args) () | ||
40 | # endif | ||
41 | #endif /*__P */ | ||
42 | |||
43 | /* Forward declaration. */ | ||
44 | struct _folder; | ||
45 | typedef struct _folder *folder_t; | ||
46 | |||
47 | /* Constructor/destructor and possible types. */ | ||
48 | extern int folder_create __P ((folder_t *, const char *)); | ||
49 | extern void folder_destroy __P ((folder_t *)); | ||
50 | |||
51 | extern int folder_open __P ((folder_t, int flag)); | ||
52 | extern int folder_close __P ((folder_t)); | ||
53 | |||
54 | extern int folder_delete_mailbox __P ((folder_t, const char *)); | ||
55 | |||
56 | extern int folder_list __P ((folder_t, list_t *list)); | ||
57 | |||
58 | /* Stream settings. */ | ||
59 | extern int folder_get_stream __P ((folder_t, stream_t *)); | ||
60 | extern int folder_set_stream __P ((folder_t, stream_t)); | ||
61 | |||
62 | /* Notifications. */ | ||
63 | extern int folder_get_observable __P ((folder_t, observable_t *)); | ||
64 | extern int folder_set_observable __P ((folder_t, observable_t)); | ||
65 | extern int folder_get_debug __P ((folder_t, debug_t *)); | ||
66 | extern int folder_set_debug __P ((folder_t, debug_t)); | ||
67 | |||
68 | /* Authentication. */ | ||
69 | extern int folder_get_authority __P ((folder_t, authority_t *)); | ||
70 | extern int folder_set_authority __P ((folder_t, authority_t)); | ||
71 | extern int folder_get_ticket __P ((folder_t, ticket_t *)); | ||
72 | extern int folder_set_ticket __P ((folder_t, ticket_t)); | ||
73 | |||
74 | /* URL. */ | ||
75 | extern int folder_get_url __P ((folder_t, url_t *)); | ||
76 | extern int folder_set_url __P ((folder_t, url_t)); | ||
77 | |||
78 | extern int folder_decremente __P ((folder_t)); | ||
79 | |||
80 | |||
81 | #ifdef __cplusplus | ||
82 | } | ||
83 | #endif | ||
84 | |||
85 | #endif /* _MAILUTILS_FOLDER_H */ |
... | @@ -39,6 +39,7 @@ extern int list_create __P ((list_t *)); | ... | @@ -39,6 +39,7 @@ extern int list_create __P ((list_t *)); |
39 | extern void list_destroy __P ((list_t *)); | 39 | extern void list_destroy __P ((list_t *)); |
40 | extern int list_append __P ((list_t, void *item)); | 40 | extern int list_append __P ((list_t, void *item)); |
41 | extern int list_prepend __P ((list_t, void *item)); | 41 | extern int list_prepend __P ((list_t, void *item)); |
42 | extern int list_is_empty __P ((list_t)); | ||
42 | extern int list_count __P ((list_t, size_t *pcount)); | 43 | extern int list_count __P ((list_t, size_t *pcount)); |
43 | extern int list_remove __P ((list_t, void *item)); | 44 | extern int list_remove __P ((list_t, void *item)); |
44 | extern int list_get __P ((list_t, size_t _index, void **pitem)); | 45 | extern int list_get __P ((list_t, size_t _index, void **pitem)); | ... | ... |
... | @@ -46,7 +46,7 @@ struct _mailbox; | ... | @@ -46,7 +46,7 @@ struct _mailbox; |
46 | typedef struct _mailbox *mailbox_t; | 46 | typedef struct _mailbox *mailbox_t; |
47 | 47 | ||
48 | /* Constructor/destructor and possible types. */ | 48 | /* Constructor/destructor and possible types. */ |
49 | extern int mailbox_create __P ((mailbox_t *, const char *, int)); | 49 | extern int mailbox_create __P ((mailbox_t *, const char *)); |
50 | extern void mailbox_destroy __P ((mailbox_t *)); | 50 | extern void mailbox_destroy __P ((mailbox_t *)); |
51 | extern int mailbox_create_default __P ((mailbox_t *, const char *)); | 51 | extern int mailbox_create_default __P ((mailbox_t *, const char *)); |
52 | 52 | ||
... | @@ -73,6 +73,8 @@ extern int mailbox_get_locker __P ((mailbox_t, locker_t *)); | ... | @@ -73,6 +73,8 @@ extern int mailbox_get_locker __P ((mailbox_t, locker_t *)); |
73 | extern int mailbox_set_locker __P ((mailbox_t, locker_t)); | 73 | extern int mailbox_set_locker __P ((mailbox_t, locker_t)); |
74 | 74 | ||
75 | /* Authentication. */ | 75 | /* Authentication. */ |
76 | extern int mailbox_get_authority __P ((mailbox_t, authority_t *)); | ||
77 | extern int mailbox_set_authority __P ((mailbox_t, authority_t)); | ||
76 | extern int mailbox_get_ticket __P ((mailbox_t, ticket_t *)); | 78 | extern int mailbox_get_ticket __P ((mailbox_t, ticket_t *)); |
77 | extern int mailbox_set_ticket __P ((mailbox_t, ticket_t)); | 79 | extern int mailbox_set_ticket __P ((mailbox_t, ticket_t)); |
78 | 80 | ... | ... |
... | @@ -57,8 +57,7 @@ extern int mailer_set_stream __P ((mailer_t, stream_t)); | ... | @@ -57,8 +57,7 @@ extern int mailer_set_stream __P ((mailer_t, stream_t)); |
57 | extern int mailer_get_debug __P ((mailer_t, debug_t *)); | 57 | extern int mailer_get_debug __P ((mailer_t, debug_t *)); |
58 | extern int mailer_set_debug __P ((mailer_t, debug_t)); | 58 | extern int mailer_set_debug __P ((mailer_t, debug_t)); |
59 | 59 | ||
60 | extern int mailer_attach __P ((mailer_t, observer_t)); | 60 | extern int mailer_get_observable __P ((mailer_t, observable_t *)); |
61 | extern int mailer_detach __P ((mailer_t, observer_t)); | ||
62 | 61 | ||
63 | extern int mailer_get_url __P ((mailer_t, url_t *)); | 62 | extern int mailer_get_url __P ((mailer_t, url_t *)); |
64 | 63 | ... | ... |
... | @@ -38,6 +38,7 @@ typedef struct _observer* observer_t; | ... | @@ -38,6 +38,7 @@ typedef struct _observer* observer_t; |
38 | typedef struct _observable* observable_t; | 38 | typedef struct _observable* observable_t; |
39 | 39 | ||
40 | #define MU_EVT_MAILBOX_DESTROY 0x001 | 40 | #define MU_EVT_MAILBOX_DESTROY 0x001 |
41 | #define MU_EVT_FOLDER_DESTROY 0x001 | ||
41 | #define MU_EVT_MAILER_DESTROY 0x002 | 42 | #define MU_EVT_MAILER_DESTROY 0x002 |
42 | #define MU_EVT_MESSAGE_DESTROY 0x004 | 43 | #define MU_EVT_MESSAGE_DESTROY 0x004 |
43 | #define MU_EVT_MESSAGE_ADD 0x008 | 44 | #define MU_EVT_MESSAGE_ADD 0x008 |
... | @@ -57,7 +58,7 @@ extern int observer_set_flags __P ((observer_t, int flags)); | ... | @@ -57,7 +58,7 @@ extern int observer_set_flags __P ((observer_t, int flags)); |
57 | extern int observable_create __P ((observable_t *, void *owner)); | 58 | extern int observable_create __P ((observable_t *, void *owner)); |
58 | extern void observable_destroy __P ((observable_t *, void *owner)); | 59 | extern void observable_destroy __P ((observable_t *, void *owner)); |
59 | extern void * observable_get_owner __P ((observable_t)); | 60 | extern void * observable_get_owner __P ((observable_t)); |
60 | extern int observable_attach __P ((observable_t, observer_t observer)); | 61 | extern int observable_attach __P ((observable_t, size_t type, observer_t observer)); |
61 | extern int observable_detach __P ((observable_t, observer_t observer)); | 62 | extern int observable_detach __P ((observable_t, observer_t observer)); |
62 | extern int observable_notify __P ((observable_t, int type)); | 63 | extern int observable_notify __P ((observable_t, int type)); |
63 | 64 | ... | ... |
... | @@ -23,6 +23,7 @@ | ... | @@ -23,6 +23,7 @@ |
23 | #include <mailutils/url.h> | 23 | #include <mailutils/url.h> |
24 | #include <mailutils/mailbox.h> | 24 | #include <mailutils/mailbox.h> |
25 | #include <mailutils/mailer.h> | 25 | #include <mailutils/mailer.h> |
26 | #include <mailutils/folder.h> | ||
26 | #include <mailutils/list.h> | 27 | #include <mailutils/list.h> |
27 | 28 | ||
28 | #ifndef __P | 29 | #ifndef __P |
... | @@ -41,6 +42,8 @@ struct mailbox_entry; | ... | @@ -41,6 +42,8 @@ struct mailbox_entry; |
41 | typedef struct mailbox_entry* mailbox_entry_t; | 42 | typedef struct mailbox_entry* mailbox_entry_t; |
42 | struct mailer_entry; | 43 | struct mailer_entry; |
43 | typedef struct mailer_entry* mailer_entry_t; | 44 | typedef struct mailer_entry* mailer_entry_t; |
45 | struct folder_entry; | ||
46 | typedef struct folder_entry* folder_entry_t; | ||
44 | struct _registrar_record; | 47 | struct _registrar_record; |
45 | typedef struct _registrar_record* registrar_record_t; | 48 | typedef struct _registrar_record* registrar_record_t; |
46 | 49 | ||
... | @@ -54,6 +57,11 @@ struct mailer_entry | ... | @@ -54,6 +57,11 @@ struct mailer_entry |
54 | int (*_url_init) __P ((url_t)); | 57 | int (*_url_init) __P ((url_t)); |
55 | int (*_mailer_init) __P ((mailer_t)); | 58 | int (*_mailer_init) __P ((mailer_t)); |
56 | }; | 59 | }; |
60 | struct folder_entry | ||
61 | { | ||
62 | int (*_url_init) __P ((url_t)); | ||
63 | int (*_folder_init) __P ((folder_t)); | ||
64 | }; | ||
57 | 65 | ||
58 | struct _record; | 66 | struct _record; |
59 | typedef struct _record* record_t; | 67 | typedef struct _record* record_t; |
... | @@ -77,6 +85,10 @@ extern int record_get_mailer __P ((record_t, mailer_entry_t *)); | ... | @@ -77,6 +85,10 @@ extern int record_get_mailer __P ((record_t, mailer_entry_t *)); |
77 | extern int record_set_mailer __P ((record_t, mailer_entry_t)); | 85 | extern int record_set_mailer __P ((record_t, mailer_entry_t)); |
78 | extern int record_set_get_mailer __P ((record_t, int (*_get_mailer) | 86 | extern int record_set_get_mailer __P ((record_t, int (*_get_mailer) |
79 | __P ((mailer_entry_t *)))); | 87 | __P ((mailer_entry_t *)))); |
88 | extern int record_get_folder __P ((record_t, folder_entry_t *)); | ||
89 | extern int record_set_folder __P ((record_t, folder_entry_t)); | ||
90 | extern int record_set_get_folder __P ((record_t, int (*_get_folder) | ||
91 | __P ((folder_entry_t *)))); | ||
80 | 92 | ||
81 | #define MU_POP_PORT 110 | 93 | #define MU_POP_PORT 110 |
82 | #define MU_POP_SCHEME "pop://" | 94 | #define MU_POP_SCHEME "pop://" |
... | @@ -85,6 +97,13 @@ extern int url_pop_init __P ((url_t)); | ... | @@ -85,6 +97,13 @@ extern int url_pop_init __P ((url_t)); |
85 | extern mailbox_entry_t pop_entry; | 97 | extern mailbox_entry_t pop_entry; |
86 | extern record_t pop_record; | 98 | extern record_t pop_record; |
87 | 99 | ||
100 | #define MU_IMAP_PORT 143 | ||
101 | #define MU_IMAP_SCHEME "imap://" | ||
102 | #define MU_IMAP_SCHEME_LEN 7 | ||
103 | extern int url_imap_init __P ((url_t)); | ||
104 | extern folder_entry_t imap_entry; | ||
105 | extern record_t imap_record; | ||
106 | |||
88 | #define MU_MBOX_SCHEME "mbox:" | 107 | #define MU_MBOX_SCHEME "mbox:" |
89 | #define MU_MBOX_SCHEME_LEN 5 | 108 | #define MU_MBOX_SCHEME_LEN 5 |
90 | extern int url_mbox_init __P ((url_t)); | 109 | extern int url_mbox_init __P ((url_t)); | ... | ... |
... | @@ -55,7 +55,7 @@ mail_copy (int argc, char **argv) | ... | @@ -55,7 +55,7 @@ mail_copy (int argc, char **argv) |
55 | /* filename = login name part */ | 55 | /* filename = login name part */ |
56 | } | 56 | } |
57 | 57 | ||
58 | mailbox_create (&mbx, filename, 0); | 58 | mailbox_create (&mbx, filename); |
59 | mailbox_open (mbx, MU_STREAM_WRITE | MU_STREAM_CREAT); | 59 | mailbox_open (mbx, MU_STREAM_WRITE | MU_STREAM_CREAT); |
60 | 60 | ||
61 | if (num > 0) | 61 | if (num > 0) | ... | ... |
... | @@ -208,7 +208,7 @@ main (int argc, char **argv) | ... | @@ -208,7 +208,7 @@ main (int argc, char **argv) |
208 | if (mailbox_create_default (&mbox, args.user) != 0) | 208 | if (mailbox_create_default (&mbox, args.user) != 0) |
209 | exit (EXIT_FAILURE); | 209 | exit (EXIT_FAILURE); |
210 | } | 210 | } |
211 | else if (mailbox_create (&mbox, args.file, 0) != 0) | 211 | else if (mailbox_create (&mbox, args.file) != 0) |
212 | exit (EXIT_FAILURE); | 212 | exit (EXIT_FAILURE); |
213 | 213 | ||
214 | if (mailbox_open (mbox, MU_STREAM_READ) != 0) | 214 | if (mailbox_open (mbox, MU_STREAM_READ) != 0) | ... | ... |
... | @@ -302,6 +302,8 @@ address_destroy (address_t *paddress) | ... | @@ -302,6 +302,8 @@ address_destroy (address_t *paddress) |
302 | address_t current; | 302 | address_t current; |
303 | for (; address; address = current) | 303 | for (; address; address = current) |
304 | { | 304 | { |
305 | if (address->addr) | ||
306 | free (address->addr); | ||
305 | if (address->comments) | 307 | if (address->comments) |
306 | free (address->comments); | 308 | free (address->comments); |
307 | if (address->personal) | 309 | if (address->personal) | ... | ... |
... | @@ -71,8 +71,8 @@ ticket_destroy (ticket_t *pticket, void *owner) | ... | @@ -71,8 +71,8 @@ ticket_destroy (ticket_t *pticket, void *owner) |
71 | free (ticket->type); | 71 | free (ticket->type); |
72 | free (ticket); | 72 | free (ticket); |
73 | } | 73 | } |
74 | *pticket = NULL; | ||
74 | } | 75 | } |
75 | *pticket = NULL; | ||
76 | } | 76 | } |
77 | 77 | ||
78 | void * | 78 | void * |
... | @@ -145,6 +145,8 @@ ticket_set_type (ticket_t ticket, char *type) | ... | @@ -145,6 +145,8 @@ ticket_set_type (ticket_t ticket, char *type) |
145 | { | 145 | { |
146 | if (ticket == NULL) | 146 | if (ticket == NULL) |
147 | return EINVAL; | 147 | return EINVAL; |
148 | if (ticket->type) | ||
149 | free (ticket->type); | ||
148 | ticket->type = strdup ((type) ? type : ""); | 150 | ticket->type = strdup ((type) ? type : ""); |
149 | return 0; | 151 | return 0; |
150 | } | 152 | } |
... | @@ -190,7 +192,8 @@ authority_set_ticket (authority_t authority, ticket_t ticket) | ... | @@ -190,7 +192,8 @@ authority_set_ticket (authority_t authority, ticket_t ticket) |
190 | { | 192 | { |
191 | if (authority == NULL) | 193 | if (authority == NULL) |
192 | return EINVAL; | 194 | return EINVAL; |
193 | ticket_destroy (&(authority->ticket), authority); | 195 | if (authority->ticket) |
196 | ticket_destroy (&(authority->ticket), authority); | ||
194 | authority->ticket = ticket; | 197 | authority->ticket = ticket; |
195 | return 0; | 198 | return 0; |
196 | } | 199 | } | ... | ... |
mailbox/folder.c
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Library Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | |||
22 | #include <errno.h> | ||
23 | #include <stdlib.h> | ||
24 | |||
25 | #include <mailutils/registrar.h> | ||
26 | #include <mailutils/iterator.h> | ||
27 | |||
28 | #include <misc.h> | ||
29 | #include <folder0.h> | ||
30 | |||
31 | int | ||
32 | folder_create (folder_t *pfolder, const char *name) | ||
33 | { | ||
34 | int status = EINVAL; | ||
35 | record_t record = NULL; | ||
36 | folder_entry_t entry = NULL; | ||
37 | iterator_t iterator; | ||
38 | list_t list; | ||
39 | int found = 0; | ||
40 | |||
41 | if (pfolder == NULL) | ||
42 | return EINVAL; | ||
43 | |||
44 | /* Look in the registrar, for a match */ | ||
45 | registrar_get_list (&list); | ||
46 | status = iterator_create (&iterator, list); | ||
47 | if (status != 0) | ||
48 | return status; | ||
49 | for (iterator_first (iterator); !iterator_is_done (iterator); | ||
50 | iterator_next (iterator)) | ||
51 | { | ||
52 | iterator_current (iterator, (void **)&record); | ||
53 | if (record_is_scheme (record, name)) | ||
54 | { | ||
55 | record_get_folder (record, &entry); | ||
56 | if (entry) | ||
57 | { | ||
58 | found = 1; | ||
59 | break; | ||
60 | } | ||
61 | } | ||
62 | } | ||
63 | iterator_destroy (&iterator); | ||
64 | |||
65 | if (found) | ||
66 | { | ||
67 | url_t url = NULL; | ||
68 | folder_t folder = NULL; | ||
69 | |||
70 | /* Allocate memory for mbox. */ | ||
71 | folder = calloc (1, sizeof (*folder)); | ||
72 | if (folder == NULL) | ||
73 | return ENOMEM; | ||
74 | |||
75 | /* Initialize the internal lock, now so the concrete mailbox | ||
76 | could use it. */ | ||
77 | status = RWLOCK_INIT (&(folder->rwlock), NULL); | ||
78 | if (status != 0) | ||
79 | { | ||
80 | folder_destroy (&folder); | ||
81 | return status; | ||
82 | } | ||
83 | |||
84 | /* Parse the url, it may be a bad one and we should bailout if this | ||
85 | failed. */ | ||
86 | if ((status = url_create (&url, name)) != 0 | ||
87 | || (status = entry->_url_init (url)) != 0) | ||
88 | { | ||
89 | folder_destroy (&folder); | ||
90 | return status; | ||
91 | } | ||
92 | folder->url = url; | ||
93 | |||
94 | /* Create the concrete folder type. */ | ||
95 | status = entry->_folder_init (folder); | ||
96 | if (status != 0) | ||
97 | { | ||
98 | folder_destroy (&folder); | ||
99 | } | ||
100 | else | ||
101 | *pfolder = folder; | ||
102 | } | ||
103 | else | ||
104 | status = ENOENT; | ||
105 | |||
106 | return status; | ||
107 | } | ||
108 | |||
109 | void | ||
110 | folder_destroy (folder_t *pfolder) | ||
111 | { | ||
112 | if (pfolder && *pfolder) | ||
113 | { | ||
114 | folder_t folder = *pfolder; | ||
115 | int destroy_lock = 0; | ||
116 | #ifdef WITH_PTHREAD | ||
117 | pthread_rwlock_t rwlock = folder->rwlock; | ||
118 | #endif | ||
119 | RWLOCK_WRLOCK (&(rwlock)); | ||
120 | if (folder_decremente (folder) == 0) | ||
121 | { | ||
122 | RWLOCK_UNLOCK (&(rwlock)); | ||
123 | destroy_lock = 1; | ||
124 | /* Notify the observers. */ | ||
125 | if (folder->observable) | ||
126 | { | ||
127 | observable_notify (folder->observable, MU_EVT_FOLDER_DESTROY); | ||
128 | observable_destroy (&(folder->observable), folder); | ||
129 | } | ||
130 | if (folder->_destroy) | ||
131 | folder->_destroy (folder); | ||
132 | RWLOCK_WRLOCK (&(rwlock)); | ||
133 | if (folder->ticket) | ||
134 | ticket_destroy (&(folder->ticket), folder); | ||
135 | if (folder->authority) | ||
136 | authority_destroy (&(folder->authority), folder); | ||
137 | if (folder->stream) | ||
138 | stream_destroy (&(folder->stream), folder); | ||
139 | if (folder->url) | ||
140 | url_destroy (&(folder->url)); | ||
141 | free (folder); | ||
142 | } | ||
143 | RWLOCK_UNLOCK (&(rwlock)); | ||
144 | if (destroy_lock) | ||
145 | RWLOCK_DESTROY (&(rwlock)); | ||
146 | *pfolder = NULL; | ||
147 | } | ||
148 | } | ||
149 | |||
150 | int | ||
151 | folder_open (folder_t folder, int flags) | ||
152 | { | ||
153 | if (folder == NULL || folder->_open == NULL) | ||
154 | return ENOSYS; | ||
155 | return folder->_open (folder, flags); | ||
156 | } | ||
157 | |||
158 | int | ||
159 | folder_close (folder_t folder) | ||
160 | { | ||
161 | if (folder == NULL || folder->_close == NULL) | ||
162 | return ENOSYS; | ||
163 | return folder->_close (folder); | ||
164 | } | ||
165 | |||
166 | int | ||
167 | folder_set_stream (folder_t folder, stream_t stream) | ||
168 | { | ||
169 | if (folder == NULL) | ||
170 | return EINVAL; | ||
171 | if (folder->stream) | ||
172 | stream_destroy (&(folder->stream), folder); | ||
173 | folder->stream = stream; | ||
174 | return 0; | ||
175 | } | ||
176 | |||
177 | int | ||
178 | folder_get_stream (folder_t folder, stream_t *pstream) | ||
179 | { | ||
180 | if (folder == NULL || pstream == NULL) | ||
181 | return EINVAL; | ||
182 | *pstream = folder->stream; | ||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | int | ||
187 | folder_set_authority (folder_t folder, authority_t authority) | ||
188 | { | ||
189 | if (folder == NULL) | ||
190 | return EINVAL; | ||
191 | if (folder->authority) | ||
192 | authority_destroy (&(folder->authority), folder); | ||
193 | folder->authority = authority; | ||
194 | return 0; | ||
195 | } | ||
196 | |||
197 | int | ||
198 | folder_get_authority (folder_t folder, authority_t *pauthority) | ||
199 | { | ||
200 | if (folder == NULL || pauthority == NULL) | ||
201 | return EINVAL; | ||
202 | *pauthority = folder->authority; | ||
203 | return 0; | ||
204 | } | ||
205 | |||
206 | int | ||
207 | folder_set_ticket (folder_t folder, ticket_t ticket) | ||
208 | { | ||
209 | if (folder == NULL) | ||
210 | return EINVAL; | ||
211 | if (folder->ticket) | ||
212 | ticket_destroy (&(folder->ticket), folder); | ||
213 | folder->ticket = ticket; | ||
214 | return 0; | ||
215 | } | ||
216 | |||
217 | int | ||
218 | folder_get_ticket (folder_t folder, ticket_t *pticket) | ||
219 | { | ||
220 | if (folder == NULL || pticket == NULL) | ||
221 | return EINVAL; | ||
222 | *pticket = folder->ticket; | ||
223 | return 0; | ||
224 | } | ||
225 | int | ||
226 | folder_get_observable (folder_t folder, observable_t *pobservable) | ||
227 | { | ||
228 | if (folder == NULL || pobservable == NULL) | ||
229 | return EINVAL; | ||
230 | |||
231 | if (folder->observable == NULL) | ||
232 | { | ||
233 | int status = observable_create (&(folder->observable), folder); | ||
234 | if (status != 0) | ||
235 | return status; | ||
236 | } | ||
237 | *pobservable = folder->observable; | ||
238 | return 0; | ||
239 | } | ||
240 | |||
241 | int | ||
242 | folder_set_debug (folder_t folder, debug_t debug) | ||
243 | { | ||
244 | if (folder == NULL) | ||
245 | return EINVAL; | ||
246 | if (folder->debug) | ||
247 | debug_destroy (&(folder->debug), folder); | ||
248 | folder->debug = debug; | ||
249 | return 0; | ||
250 | } | ||
251 | |||
252 | int | ||
253 | folder_get_debug (folder_t folder, debug_t *pdebug) | ||
254 | { | ||
255 | if (folder == NULL || pdebug == NULL) | ||
256 | return EINVAL; | ||
257 | if (folder->debug == NULL) | ||
258 | { | ||
259 | int status = debug_create (&(folder->debug), folder); | ||
260 | if (status != 0) | ||
261 | return status; | ||
262 | } | ||
263 | *pdebug = folder->debug; | ||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | |||
268 | int | ||
269 | folder_list (folder_t folder, list_t *plist) | ||
270 | { | ||
271 | if (folder == NULL || folder->_list == NULL) | ||
272 | return ENOSYS; | ||
273 | return folder->_list (folder, plist); | ||
274 | } | ||
275 | |||
276 | int | ||
277 | folder_delete_mailbox (folder_t folder, const char *name) | ||
278 | { | ||
279 | if (folder == NULL || folder->_delete_mailbox == NULL) | ||
280 | return ENOSYS; | ||
281 | return folder->_delete_mailbox (folder, name); | ||
282 | } | ||
283 | |||
284 | int | ||
285 | folder_decremente (folder_t folder) | ||
286 | { | ||
287 | if (folder && folder->_decremente) | ||
288 | return folder->_decremente (folder); | ||
289 | return (folder->ref--); | ||
290 | } |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _ADDRESS0_H | 18 | #ifndef _ADDRESS0_H |
19 | #define _ADDRESS_0H | 19 | #define _ADDRESS_0H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #include <mailutils/address.h> | 25 | #include <mailutils/address.h> |
22 | 26 | ||
23 | #ifndef __P | 27 | #ifndef __P | ... | ... |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _ATTRIBUTE0_H | 18 | #ifndef _ATTRIBUTE0_H |
19 | # define _ATTRIBUTE0_H | 19 | # define _ATTRIBUTE0_H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #include <mailutils/attribute.h> | 25 | #include <mailutils/attribute.h> |
22 | 26 | ||
23 | #ifdef __cplusplus | 27 | #ifdef __cplusplus | ... | ... |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _AUTH0_H | 18 | #ifndef _AUTH0_H |
19 | #define _AUTH0_H | 19 | #define _AUTH0_H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #include <mailutils/auth.h> | 25 | #include <mailutils/auth.h> |
22 | #include <sys/types.h> | 26 | #include <sys/types.h> |
23 | 27 | ... | ... |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _BIO_H | 18 | #ifndef _BIO_H |
19 | # define _BIO_H | 19 | # define _BIO_H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #include <sys/types.h> | 25 | #include <sys/types.h> |
22 | #include <mailutils/stream.h> | 26 | #include <mailutils/stream.h> |
23 | 27 | ... | ... |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _BODY0_H | 18 | #ifndef _BODY0_H |
19 | #define _BODY0_H | 19 | #define _BODY0_H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #include <mailutils/stream.h> | 25 | #include <mailutils/stream.h> |
22 | #include <mailutils/body.h> | 26 | #include <mailutils/body.h> |
23 | 27 | ... | ... |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _MAILUTILS_DEBUG0_H | 18 | #ifndef _MAILUTILS_DEBUG0_H |
19 | #define _MAILUTILS_DEBUG0_H | 19 | #define _MAILUTILS_DEBUG0_H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #ifndef __P | 25 | #ifndef __P |
22 | #ifdef __STDC__ | 26 | #ifdef __STDC__ |
23 | #define __P(args) args | 27 | #define __P(args) args | ... | ... |
mailbox/include/folder0.h
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #ifndef _FOLDER_H | ||
19 | #define _FOLDER0_H | ||
20 | |||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
25 | #ifdef HAVE_PTHREAD_H | ||
26 | # define __USE_UNIX98 /* ?? */ | ||
27 | # include <pthread.h> | ||
28 | #endif | ||
29 | |||
30 | #include <sys/types.h> | ||
31 | #include <stdio.h> | ||
32 | |||
33 | #include <mailutils/folder.h> | ||
34 | |||
35 | #ifdef __cplusplus | ||
36 | extern "C" { | ||
37 | #endif | ||
38 | |||
39 | #ifndef __P | ||
40 | # ifdef __STDC__ | ||
41 | # define __P(args) args | ||
42 | # else | ||
43 | # define __P(args) () | ||
44 | # endif | ||
45 | #endif /*__P */ | ||
46 | |||
47 | struct _folder | ||
48 | { | ||
49 | /* Data */ | ||
50 | ticket_t ticket; | ||
51 | authority_t authority; | ||
52 | observable_t observable; | ||
53 | debug_t debug; | ||
54 | stream_t stream; | ||
55 | url_t url; | ||
56 | int flags; | ||
57 | size_t ref; | ||
58 | size_t uid; | ||
59 | |||
60 | #ifdef WITH_PTHREAD | ||
61 | pthread_rwlock_t rwlock; | ||
62 | #endif | ||
63 | |||
64 | /* Back pointer to the specific mailbox */ | ||
65 | void *data; | ||
66 | |||
67 | /* Public methods */ | ||
68 | |||
69 | int (*_init) __P ((folder_t)); | ||
70 | void (*_destroy) __P ((folder_t)); | ||
71 | |||
72 | int (*_open) __P ((folder_t, int flag)); | ||
73 | int (*_close) __P ((folder_t)); | ||
74 | int (*_list) __P ((folder_t, list_t *)); | ||
75 | int (*_delete_mailbox) __P ((folder_t, const char *)); | ||
76 | int (*_decremente) __P ((folder_t)); | ||
77 | }; | ||
78 | |||
79 | /* To manipulate mailbox rwlock. */ | ||
80 | extern int folder_rdlock __P ((folder_t)); | ||
81 | extern int folder_wrlock __P ((folder_t)); | ||
82 | extern int folder_unlock __P ((folder_t)); | ||
83 | |||
84 | #ifdef __cplusplus | ||
85 | } | ||
86 | #endif | ||
87 | |||
88 | #endif /* _MAILBOX0_H */ |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _HEADER0_H | 18 | #ifndef _HEADER0_H |
19 | #define _HEADER0_H | 19 | #define _HEADER0_H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #include <mailutils/header.h> | 25 | #include <mailutils/header.h> |
22 | #include <sys/types.h> | 26 | #include <sys/types.h> |
23 | 27 | ... | ... |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _ITERATOR0_H | 18 | #ifndef _ITERATOR0_H |
19 | #define _ITERATOR0_H | 19 | #define _ITERATOR0_H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #include <mailutils/iterator.h> | 25 | #include <mailutils/iterator.h> |
22 | 26 | ||
23 | #ifndef __P | 27 | #ifndef __P | ... | ... |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _LIST0_H | 18 | #ifndef _LIST0_H |
19 | #define _LIST0_H | 19 | #define _LIST0_H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #ifdef HAVE_PTHREAD_H | 25 | #ifdef HAVE_PTHREAD_H |
22 | # define __USE_UNIX98 /* ?? */ | 26 | # define __USE_UNIX98 /* ?? */ |
23 | # include <pthread.h> | 27 | # include <pthread.h> | ... | ... |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _MAILBOX0_H | 18 | #ifndef _MAILBOX0_H |
19 | #define _MAILBOX0_H | 19 | #define _MAILBOX0_H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #ifdef HAVE_PTHREAD_H | 25 | #ifdef HAVE_PTHREAD_H |
22 | # define __USE_UNIX98 /* ?? */ | 26 | # define __USE_UNIX98 /* ?? */ |
23 | # include <pthread.h> | 27 | # include <pthread.h> |
... | @@ -27,6 +31,7 @@ | ... | @@ -27,6 +31,7 @@ |
27 | #include <stdio.h> | 31 | #include <stdio.h> |
28 | 32 | ||
29 | #include <mailutils/mailbox.h> | 33 | #include <mailutils/mailbox.h> |
34 | #include <mailutils/folder.h> | ||
30 | 35 | ||
31 | #ifdef __cplusplus | 36 | #ifdef __cplusplus |
32 | extern "C" { | 37 | extern "C" { |
... | @@ -50,6 +55,7 @@ struct _mailbox | ... | @@ -50,6 +55,7 @@ struct _mailbox |
50 | locker_t locker; | 55 | locker_t locker; |
51 | stream_t stream; | 56 | stream_t stream; |
52 | url_t url; | 57 | url_t url; |
58 | folder_t folder; | ||
53 | int flags; | 59 | int flags; |
54 | 60 | ||
55 | #ifdef WITH_PTHREAD | 61 | #ifdef WITH_PTHREAD | ... | ... |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _MAILER0_H | 18 | #ifndef _MAILER0_H |
19 | #define _MAILER0_H | 19 | #define _MAILER0_H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #include <sys/types.h> | 25 | #include <sys/types.h> |
22 | #include <mailutils/mailer.h> | 26 | #include <mailutils/mailer.h> |
23 | #ifdef HAVE_PTHREAD_H | 27 | #ifdef HAVE_PTHREAD_H | ... | ... |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _MESSAGE0_H | 18 | #ifndef _MESSAGE0_H |
19 | #define _MESSAGE0_H | 19 | #define _MESSAGE0_H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #include <mailutils/message.h> | 25 | #include <mailutils/message.h> |
22 | #include <mailutils/mime.h> | 26 | #include <mailutils/mime.h> |
23 | 27 | ... | ... |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _MIME0_H | 18 | #ifndef _MIME0_H |
19 | #define _MIME0_H | 19 | #define _MIME0_H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #include <sys/types.h> | 25 | #include <sys/types.h> |
22 | #include <mailutils/mime.h> | 26 | #include <mailutils/mime.h> |
23 | 27 | ... | ... |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _MISC_H | 18 | #ifndef _MISC_H |
19 | #define _MISC_H | 19 | #define _MISC_H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #ifdef HAVE_CONFIG_H | 25 | #ifdef HAVE_CONFIG_H |
22 | # include <config.h> | 26 | # include <config.h> |
23 | #endif | 27 | #endif | ... | ... |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _OBSERVER0_H | 18 | #ifndef _OBSERVER0_H |
19 | #define _OBSERVER0_H | 19 | #define _OBSERVER0_H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #include <mailutils/observer.h> | 25 | #include <mailutils/observer.h> |
22 | 26 | ||
23 | #ifndef __P | 27 | #ifndef __P |
... | @@ -46,6 +50,15 @@ struct _observable | ... | @@ -46,6 +50,15 @@ struct _observable |
46 | list_t list; | 50 | list_t list; |
47 | }; | 51 | }; |
48 | 52 | ||
53 | struct _event | ||
54 | { | ||
55 | size_t type; | ||
56 | observer_t observer; | ||
57 | }; | ||
58 | |||
59 | typedef struct _event *event_t; | ||
60 | |||
61 | |||
49 | 62 | ||
50 | #ifdef _cplusplus | 63 | #ifdef _cplusplus |
51 | } | 64 | } | ... | ... |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _REGISTRAR0_H | 18 | #ifndef _REGISTRAR0_H |
19 | #define _REGISTRAR0_H | 19 | #define _REGISTRAR0_H |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #include <mailutils/registrar.h> | 25 | #include <mailutils/registrar.h> |
22 | 26 | ||
23 | #ifdef __cplusplus | 27 | #ifdef __cplusplus |
... | @@ -37,11 +41,13 @@ struct _record | ... | @@ -37,11 +41,13 @@ struct _record |
37 | const char *scheme; | 41 | const char *scheme; |
38 | mailbox_entry_t mailbox; | 42 | mailbox_entry_t mailbox; |
39 | mailer_entry_t mailer; | 43 | mailer_entry_t mailer; |
44 | folder_entry_t folder; | ||
40 | int is_allocated; | 45 | int is_allocated; |
41 | void *onwer; | 46 | void *onwer; |
42 | int (*_is_scheme) __P ((record_t, const char *)); | 47 | int (*_is_scheme) __P ((record_t, const char *)); |
43 | int (*_get_mailbox) __P ((record_t, mailbox_entry_t *_mailbox)); | 48 | int (*_get_mailbox) __P ((record_t, mailbox_entry_t *_mailbox)); |
44 | int (*_get_mailer) __P ((record_t, mailer_entry_t *_mailer)); | 49 | int (*_get_mailer) __P ((record_t, mailer_entry_t *_mailer)); |
50 | int (*_get_folder) __P ((record_t, folder_entry_t *_mailer)); | ||
45 | }; | 51 | }; |
46 | 52 | ||
47 | #ifdef __cplusplus | 53 | #ifdef __cplusplus | ... | ... |
... | @@ -18,6 +18,10 @@ | ... | @@ -18,6 +18,10 @@ |
18 | #ifndef _URL0_H | 18 | #ifndef _URL0_H |
19 | #define _URL0_H 1 | 19 | #define _URL0_H 1 |
20 | 20 | ||
21 | #ifdef DMALLOC | ||
22 | # include <dmalloc.h> | ||
23 | #endif | ||
24 | |||
21 | #include <mailutils/url.h> | 25 | #include <mailutils/url.h> |
22 | 26 | ||
23 | #ifdef __cplusplus | 27 | #ifdef __cplusplus | ... | ... |
... | @@ -108,6 +108,14 @@ list_prepend (list_t list, void *item) | ... | @@ -108,6 +108,14 @@ list_prepend (list_t list, void *item) |
108 | } | 108 | } |
109 | 109 | ||
110 | int | 110 | int |
111 | list_is_empty (list_t list) | ||
112 | { | ||
113 | size_t n = 0; | ||
114 | list_count (list, &n); | ||
115 | return n; | ||
116 | } | ||
117 | |||
118 | int | ||
111 | list_count (list_t list, size_t *pcount) | 119 | list_count (list_t list, size_t *pcount) |
112 | { | 120 | { |
113 | if (list == NULL || pcount == NULL) | 121 | if (list == NULL || pcount == NULL) | ... | ... |
... | @@ -34,7 +34,7 @@ | ... | @@ -34,7 +34,7 @@ |
34 | Then we call the mailbox's >url_create() to parse the URL. Last | 34 | Then we call the mailbox's >url_create() to parse the URL. Last |
35 | initiliaze the concrete mailbox. */ | 35 | initiliaze the concrete mailbox. */ |
36 | int | 36 | int |
37 | mailbox_create (mailbox_t *pmbox, const char *name, int id) | 37 | mailbox_create (mailbox_t *pmbox, const char *name) |
38 | { | 38 | { |
39 | int status = EINVAL; | 39 | int status = EINVAL; |
40 | record_t record = NULL; | 40 | record_t record = NULL; |
... | @@ -43,7 +43,6 @@ mailbox_create (mailbox_t *pmbox, const char *name, int id) | ... | @@ -43,7 +43,6 @@ mailbox_create (mailbox_t *pmbox, const char *name, int id) |
43 | list_t list; | 43 | list_t list; |
44 | int found = 0; | 44 | int found = 0; |
45 | 45 | ||
46 | (void)id; | ||
47 | if (pmbox == NULL) | 46 | if (pmbox == NULL) |
48 | return EINVAL; | 47 | return EINVAL; |
49 | 48 | ||
... | @@ -58,10 +57,12 @@ mailbox_create (mailbox_t *pmbox, const char *name, int id) | ... | @@ -58,10 +57,12 @@ mailbox_create (mailbox_t *pmbox, const char *name, int id) |
58 | iterator_current (iterator, (void **)&record); | 57 | iterator_current (iterator, (void **)&record); |
59 | if (record_is_scheme (record, name)) | 58 | if (record_is_scheme (record, name)) |
60 | { | 59 | { |
61 | status = record_get_mailbox (record, &entry); | 60 | record_get_mailbox (record, &entry); |
62 | if (status == 0) | 61 | if (entry) |
63 | found = 1; | 62 | { |
64 | break; | 63 | found = 1; |
64 | break; | ||
65 | } | ||
65 | } | 66 | } |
66 | } | 67 | } |
67 | iterator_destroy (&iterator); | 68 | iterator_destroy (&iterator); |
... | @@ -140,6 +141,9 @@ mailbox_destroy (mailbox_t *pmbox) | ... | @@ -140,6 +141,9 @@ mailbox_destroy (mailbox_t *pmbox) |
140 | stream_destroy (&(mbox->stream), mbox); | 141 | stream_destroy (&(mbox->stream), mbox); |
141 | } | 142 | } |
142 | 143 | ||
144 | if (mbox->ticket) | ||
145 | ticket_destroy (&(mbox->ticket), mbox); | ||
146 | |||
143 | if (mbox->authority) | 147 | if (mbox->authority) |
144 | authority_destroy (&(mbox->authority), mbox); | 148 | authority_destroy (&(mbox->authority), mbox); |
145 | 149 | ||
... | @@ -152,6 +156,9 @@ mailbox_destroy (mailbox_t *pmbox) | ... | @@ -152,6 +156,9 @@ mailbox_destroy (mailbox_t *pmbox) |
152 | if (mbox->debug) | 156 | if (mbox->debug) |
153 | debug_destroy (&(mbox->debug), mbox); | 157 | debug_destroy (&(mbox->debug), mbox); |
154 | 158 | ||
159 | if (mbox->folder) | ||
160 | folder_destroy (&(mbox->folder)); | ||
161 | |||
155 | free (mbox); | 162 | free (mbox); |
156 | *pmbox = NULL; | 163 | *pmbox = NULL; |
157 | RWLOCK_UNLOCK (&(rwlock)); | 164 | RWLOCK_UNLOCK (&(rwlock)); |
... | @@ -241,7 +248,7 @@ mailbox_set_locker (mailbox_t mbox, locker_t locker) | ... | @@ -241,7 +248,7 @@ mailbox_set_locker (mailbox_t mbox, locker_t locker) |
241 | { | 248 | { |
242 | if (mbox == NULL) | 249 | if (mbox == NULL) |
243 | return EINVAL; | 250 | return EINVAL; |
244 | if (mbox->locker != NULL) | 251 | if (mbox->locker) |
245 | locker_destroy (&mbox->locker); | 252 | locker_destroy (&mbox->locker); |
246 | mbox->locker = locker; | 253 | mbox->locker = locker; |
247 | return 0; | 254 | return 0; |
... | @@ -252,8 +259,27 @@ mailbox_get_locker (mailbox_t mbox, locker_t *plocker) | ... | @@ -252,8 +259,27 @@ mailbox_get_locker (mailbox_t mbox, locker_t *plocker) |
252 | { | 259 | { |
253 | if (mbox == NULL || plocker == NULL) | 260 | if (mbox == NULL || plocker == NULL) |
254 | return EINVAL; | 261 | return EINVAL; |
255 | if (plocker) | 262 | *plocker = mbox->locker; |
256 | *plocker = mbox->locker; | 263 | return 0; |
264 | } | ||
265 | |||
266 | int | ||
267 | mailbox_set_authority (mailbox_t mbox, authority_t authority) | ||
268 | { | ||
269 | if (mbox == NULL) | ||
270 | return EINVAL; | ||
271 | if (mbox->authority) | ||
272 | authority_destroy (&(mbox->authority), mbox); | ||
273 | mbox->authority = authority; | ||
274 | return 0; | ||
275 | } | ||
276 | |||
277 | int | ||
278 | mailbox_get_authority (mailbox_t mbox, authority_t *pauthority) | ||
279 | { | ||
280 | if (mbox == NULL || pauthority == NULL) | ||
281 | return EINVAL; | ||
282 | *pauthority = mbox->authority; | ||
257 | return 0; | 283 | return 0; |
258 | } | 284 | } |
259 | 285 | ||
... | @@ -262,6 +288,8 @@ mailbox_set_ticket (mailbox_t mbox, ticket_t ticket) | ... | @@ -262,6 +288,8 @@ mailbox_set_ticket (mailbox_t mbox, ticket_t ticket) |
262 | { | 288 | { |
263 | if (mbox == NULL) | 289 | if (mbox == NULL) |
264 | return EINVAL; | 290 | return EINVAL; |
291 | if (mbox->ticket) | ||
292 | ticket_destroy (&(mbox->ticket), mbox); | ||
265 | mbox->ticket = ticket; | 293 | mbox->ticket = ticket; |
266 | return 0; | 294 | return 0; |
267 | } | 295 | } |
... | @@ -271,8 +299,7 @@ mailbox_get_ticket (mailbox_t mbox, ticket_t *pticket) | ... | @@ -271,8 +299,7 @@ mailbox_get_ticket (mailbox_t mbox, ticket_t *pticket) |
271 | { | 299 | { |
272 | if (mbox == NULL || pticket == NULL) | 300 | if (mbox == NULL || pticket == NULL) |
273 | return EINVAL; | 301 | return EINVAL; |
274 | if (pticket) | 302 | *pticket = mbox->ticket; |
275 | *pticket = mbox->ticket; | ||
276 | return 0; | 303 | return 0; |
277 | } | 304 | } |
278 | 305 | ||
... | @@ -281,6 +308,8 @@ mailbox_set_stream (mailbox_t mbox, stream_t stream) | ... | @@ -281,6 +308,8 @@ mailbox_set_stream (mailbox_t mbox, stream_t stream) |
281 | { | 308 | { |
282 | if (mbox == NULL) | 309 | if (mbox == NULL) |
283 | return EINVAL; | 310 | return EINVAL; |
311 | if (mbox->stream) | ||
312 | stream_destroy (&(mbox->stream), mbox); | ||
284 | mbox->stream = stream; | 313 | mbox->stream = stream; |
285 | return 0; | 314 | return 0; |
286 | } | 315 | } |
... | @@ -290,8 +319,7 @@ mailbox_get_stream (mailbox_t mbox, stream_t *pstream) | ... | @@ -290,8 +319,7 @@ mailbox_get_stream (mailbox_t mbox, stream_t *pstream) |
290 | { | 319 | { |
291 | if (mbox == NULL || pstream == NULL) | 320 | if (mbox == NULL || pstream == NULL) |
292 | return EINVAL; | 321 | return EINVAL; |
293 | if (pstream) | 322 | *pstream = mbox->stream; |
294 | *pstream = mbox->stream; | ||
295 | return 0; | 323 | return 0; |
296 | } | 324 | } |
297 | 325 | ||
... | @@ -316,7 +344,8 @@ mailbox_set_debug (mailbox_t mbox, debug_t debug) | ... | @@ -316,7 +344,8 @@ mailbox_set_debug (mailbox_t mbox, debug_t debug) |
316 | { | 344 | { |
317 | if (mbox == NULL) | 345 | if (mbox == NULL) |
318 | return EINVAL; | 346 | return EINVAL; |
319 | debug_destroy (&(mbox->debug), mbox); | 347 | if (mbox->debug) |
348 | debug_destroy (&(mbox->debug), mbox); | ||
320 | mbox->debug = debug; | 349 | mbox->debug = debug; |
321 | return 0; | 350 | return 0; |
322 | } | 351 | } | ... | ... |
... | @@ -184,10 +184,10 @@ mailer_get_stream (mailer_t mailer, stream_t *pstream) | ... | @@ -184,10 +184,10 @@ mailer_get_stream (mailer_t mailer, stream_t *pstream) |
184 | } | 184 | } |
185 | 185 | ||
186 | int | 186 | int |
187 | mailer_attach (mailer_t mailer, observer_t observer) | 187 | mailer_get_observable (mailer_t mailer, observable_t *pobservable) |
188 | { | 188 | { |
189 | /* FIXME: I should check for invalid types */ | 189 | /* FIXME: I should check for invalid types */ |
190 | if (mailer == NULL || observer == NULL) | 190 | if (mailer == NULL || pobservable == NULL) |
191 | return EINVAL; | 191 | return EINVAL; |
192 | 192 | ||
193 | if (mailer->observable == NULL) | 193 | if (mailer->observable == NULL) |
... | @@ -196,18 +196,8 @@ mailer_attach (mailer_t mailer, observer_t observer) | ... | @@ -196,18 +196,8 @@ mailer_attach (mailer_t mailer, observer_t observer) |
196 | if (status != 0) | 196 | if (status != 0) |
197 | return status; | 197 | return status; |
198 | } | 198 | } |
199 | return observable_attach (mailer->observable, observer); | 199 | *pobservable = mailer->observable; |
200 | } | 200 | return 0; |
201 | |||
202 | int | ||
203 | mailer_detach (mailer_t mailer, observer_t observer) | ||
204 | { | ||
205 | /* FIXME: I should check for invalid types */ | ||
206 | if (mailer == NULL || observer == NULL) | ||
207 | return EINVAL; | ||
208 | if (mailer->observable == NULL) | ||
209 | return 0; | ||
210 | return observable_detach (mailer->observable, observer); | ||
211 | } | 201 | } |
212 | 202 | ||
213 | int | 203 | int | ... | ... |
... | @@ -74,9 +74,9 @@ mailbox_create_default (mailbox_t *pmbox, const char *mail) | ... | @@ -74,9 +74,9 @@ mailbox_create_default (mailbox_t *pmbox, const char *mail) |
74 | if (mail0 == NULL) | 74 | if (mail0 == NULL) |
75 | return ENOMEM; | 75 | return ENOMEM; |
76 | sprintf (mail0, "%s/%s", _PATH_MAILDIR, user); | 76 | sprintf (mail0, "%s/%s", _PATH_MAILDIR, user); |
77 | status = mailbox_create (pmbox, mail0, 0); | 77 | status = mailbox_create (pmbox, mail0); |
78 | free (mail0); | 78 | free (mail0); |
79 | return status; | 79 | return status; |
80 | } | 80 | } |
81 | return mailbox_create (pmbox, mail, 0); | 81 | return mailbox_create (pmbox, mail); |
82 | } | 82 | } | ... | ... |
... | @@ -41,11 +41,13 @@ static struct _record _file_record = | ... | @@ -41,11 +41,13 @@ static struct _record _file_record = |
41 | MU_FILE_SCHEME, | 41 | MU_FILE_SCHEME, |
42 | &_file_entry, /* Mailbox entry. */ | 42 | &_file_entry, /* Mailbox entry. */ |
43 | NULL, /* Mailer entry. */ | 43 | NULL, /* Mailer entry. */ |
44 | NULL, /* Folder entry. */ | ||
44 | 0, /* Not malloc()ed. */ | 45 | 0, /* Not malloc()ed. */ |
45 | NULL, /* No need for an owner. */ | 46 | NULL, /* No need for an owner. */ |
46 | NULL, /* is_scheme method. */ | 47 | NULL, /* is_scheme method. */ |
47 | NULL, /* get_mailbox method. */ | 48 | NULL, /* get_mailbox method. */ |
48 | NULL /* get_mailer method. */ | 49 | NULL, /* get_mailer method. */ |
50 | NULL /* get_folder method. */ | ||
49 | }; | 51 | }; |
50 | record_t file_record = &_file_record; | 52 | record_t file_record = &_file_record; |
51 | 53 | ||
... | @@ -61,11 +63,13 @@ static struct _record _path_record = | ... | @@ -61,11 +63,13 @@ static struct _record _path_record = |
61 | MU_PATH_SCHEME, | 63 | MU_PATH_SCHEME, |
62 | &_path_entry, /* Mailbox entry. */ | 64 | &_path_entry, /* Mailbox entry. */ |
63 | NULL, /* Mailer entry. */ | 65 | NULL, /* Mailer entry. */ |
66 | NULL, /* Folder entry. */ | ||
64 | 0, /* Not malloc()ed. */ | 67 | 0, /* Not malloc()ed. */ |
65 | NULL, /* No need for an owner. */ | 68 | NULL, /* No need for an owner. */ |
66 | NULL, /* is_scheme method. */ | 69 | NULL, /* is_scheme method. */ |
67 | NULL, /* get_mailbox method. */ | 70 | NULL, /* get_mailbox method. */ |
68 | NULL /* get_mailer method. */ | 71 | NULL, /* get_mailer method. */ |
72 | NULL /* get_folder method. */ | ||
69 | }; | 73 | }; |
70 | record_t path_record = &_path_record; | 74 | record_t path_record = &_path_record; |
71 | 75 | ... | ... |
... | @@ -60,11 +60,13 @@ static struct _record _mbox_record = | ... | @@ -60,11 +60,13 @@ static struct _record _mbox_record = |
60 | MU_MBOX_SCHEME, | 60 | MU_MBOX_SCHEME, |
61 | &_mbox_entry, /* Mailbox entry. */ | 61 | &_mbox_entry, /* Mailbox entry. */ |
62 | NULL, /* Mailer entry. */ | 62 | NULL, /* Mailer entry. */ |
63 | NULL, /* Folder entry. */ | ||
63 | 0, /* Not malloc()ed. */ | 64 | 0, /* Not malloc()ed. */ |
64 | NULL, /* No need for an owner. */ | 65 | NULL, /* No need for an owner. */ |
65 | NULL, /* is_scheme method. */ | 66 | NULL, /* is_scheme method. */ |
66 | NULL, /* get_mailbox method. */ | 67 | NULL, /* get_mailbox method. */ |
67 | NULL /* get_mailer method. */ | 68 | NULL, /* get_mailer method. */ |
69 | NULL /* get_folder method. */ | ||
68 | }; | 70 | }; |
69 | record_t mbox_record = &_mbox_record; | 71 | record_t mbox_record = &_mbox_record; |
70 | 72 | ||
... | @@ -249,7 +251,7 @@ mbox_destroy (mailbox_t mailbox) | ... | @@ -249,7 +251,7 @@ mbox_destroy (mailbox_t mailbox) |
249 | free (mud->umessages); | 251 | free (mud->umessages); |
250 | if (mud->name) | 252 | if (mud->name) |
251 | free (mud->name); | 253 | free (mud->name); |
252 | free (mailbox->data); | 254 | free (mud); |
253 | mailbox->data = NULL; | 255 | mailbox->data = NULL; |
254 | mailbox_unlock (mailbox); | 256 | mailbox_unlock (mailbox); |
255 | } | 257 | } | ... | ... |
... | @@ -50,11 +50,13 @@ static struct _record _pop_record = | ... | @@ -50,11 +50,13 @@ static struct _record _pop_record = |
50 | MU_POP_SCHEME, | 50 | MU_POP_SCHEME, |
51 | &_pop_entry, /* Mailbox entry. */ | 51 | &_pop_entry, /* Mailbox entry. */ |
52 | NULL, /* Mailer entry. */ | 52 | NULL, /* Mailer entry. */ |
53 | NULL, /* folder entry. */ | ||
53 | 0, /* Not malloc()ed. */ | 54 | 0, /* Not malloc()ed. */ |
54 | NULL, /* No need for an owner. */ | 55 | NULL, /* No need for an owner. */ |
55 | NULL, /* is_scheme method. */ | 56 | NULL, /* is_scheme method. */ |
56 | NULL, /* get_mailbox method. */ | 57 | NULL, /* get_mailbox method. */ |
57 | NULL /* get_mailer method. */ | 58 | NULL, /* get_mailer method. */ |
59 | NULL /* get_folder method. */ | ||
58 | }; | 60 | }; |
59 | 61 | ||
60 | /* We export two functions: url parsing and the initialisation of | 62 | /* We export two functions: url parsing and the initialisation of |
... | @@ -312,10 +314,10 @@ pop_destroy (mailbox_t mbox) | ... | @@ -312,10 +314,10 @@ pop_destroy (mailbox_t mbox) |
312 | } | 314 | } |
313 | } | 315 | } |
314 | bio_destroy (&(mpd->bio)); | 316 | bio_destroy (&(mpd->bio)); |
315 | free (mpd->buffer); | 317 | if (mpd->buffer) |
316 | mpd->buffer = NULL; | 318 | free (mpd->buffer); |
317 | free (mpd->pmessages); | 319 | if (mpd->pmessages) |
318 | mpd->pmessages = NULL; | 320 | free (mpd->pmessages); |
319 | free (mpd); | 321 | free (mpd); |
320 | mbox->data = NULL; | 322 | mbox->data = NULL; |
321 | mailbox_unlock (mbox); | 323 | mailbox_unlock (mbox); |
... | @@ -335,9 +337,8 @@ pop_user (authority_t auth) | ... | @@ -335,9 +337,8 @@ pop_user (authority_t auth) |
335 | { | 337 | { |
336 | case POP_AUTH: | 338 | case POP_AUTH: |
337 | authority_get_ticket (auth, &ticket); | 339 | authority_get_ticket (auth, &ticket); |
338 | /* Fetch the user/passwd from them. */ | 340 | /* Fetch the user from them. */ |
339 | ticket_pop (ticket, "Pop User: ", &mpd->user); | 341 | ticket_pop (ticket, "Pop User: ", &mpd->user); |
340 | ticket_pop (ticket, "Pop Passwd: ", &mpd->passwd); | ||
341 | status = pop_writeline (mpd, "USER %s\r\n", mpd->user); | 342 | status = pop_writeline (mpd, "USER %s\r\n", mpd->user); |
342 | CHECK_ERROR_CLOSE(mbox, mpd, status); | 343 | CHECK_ERROR_CLOSE(mbox, mpd, status); |
343 | MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); | 344 | MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); |
... | @@ -360,9 +361,12 @@ pop_user (authority_t auth) | ... | @@ -360,9 +361,12 @@ pop_user (authority_t auth) |
360 | { | 361 | { |
361 | observable_t observable = NULL; | 362 | observable_t observable = NULL; |
362 | mailbox_get_observable (mbox, &observable); | 363 | mailbox_get_observable (mbox, &observable); |
364 | CLEAR_STATE (mpd); | ||
363 | observable_notify (observable, MU_EVT_AUTHORITY_FAILED); | 365 | observable_notify (observable, MU_EVT_AUTHORITY_FAILED); |
364 | CHECK_ERROR_CLOSE (mbox, mpd, EACCES); | 366 | CHECK_ERROR_CLOSE (mbox, mpd, EACCES); |
365 | } | 367 | } |
368 | /* Fetch the passwd from them. */ | ||
369 | ticket_pop (ticket, "Pop Passwd: ", &mpd->passwd); | ||
366 | status = pop_writeline (mpd, "PASS %s\r\n", mpd->passwd); | 370 | status = pop_writeline (mpd, "PASS %s\r\n", mpd->passwd); |
367 | /* We have to nuke the passwd. */ | 371 | /* We have to nuke the passwd. */ |
368 | memset (mpd->passwd, 0, strlen (mpd->passwd)); | 372 | memset (mpd->passwd, 0, strlen (mpd->passwd)); |
... | @@ -389,6 +393,7 @@ pop_user (authority_t auth) | ... | @@ -389,6 +393,7 @@ pop_user (authority_t auth) |
389 | { | 393 | { |
390 | observable_t observable = NULL; | 394 | observable_t observable = NULL; |
391 | mailbox_get_observable (mbox, &observable); | 395 | mailbox_get_observable (mbox, &observable); |
396 | CLEAR_STATE (mpd); | ||
392 | observable_notify (observable, MU_EVT_AUTHORITY_FAILED); | 397 | observable_notify (observable, MU_EVT_AUTHORITY_FAILED); |
393 | CHECK_ERROR_CLOSE (mbox, mpd, EACCES); | 398 | CHECK_ERROR_CLOSE (mbox, mpd, EACCES); |
394 | } | 399 | } |
... | @@ -435,13 +440,18 @@ pop_open (mailbox_t mbox, int flags) | ... | @@ -435,13 +440,18 @@ pop_open (mailbox_t mbox, int flags) |
435 | if (mpd->buffer == NULL) | 440 | if (mpd->buffer == NULL) |
436 | { | 441 | { |
437 | mpd->buflen = 255; | 442 | mpd->buflen = 255; |
438 | mpd->buffer = malloc (mpd->buflen + 1); | 443 | mpd->buffer = calloc (mpd->buflen + 1, sizeof (char)); |
439 | if (mpd->buffer == NULL) | 444 | if (mpd->buffer == NULL) |
440 | { | 445 | { |
441 | CHECK_ERROR (mpd, ENOMEM); | 446 | CHECK_ERROR (mpd, ENOMEM); |
442 | } | 447 | } |
443 | mpd->ptr = mpd->buffer; | 448 | mpd->ptr = mpd->buffer; |
444 | } | 449 | } |
450 | else | ||
451 | { | ||
452 | memset (mpd->buffer, '\0', mpd->buflen); | ||
453 | mpd->ptr = mpd->buffer; | ||
454 | } | ||
445 | 455 | ||
446 | /* Create the networking stack. */ | 456 | /* Create the networking stack. */ |
447 | if (mbox->stream == NULL) | 457 | if (mbox->stream == NULL) |
... | @@ -479,19 +489,22 @@ pop_open (mailbox_t mbox, int flags) | ... | @@ -479,19 +489,22 @@ pop_open (mailbox_t mbox, int flags) |
479 | CHECK_ERROR_CLOSE (mbox, mpd, EACCES); | 489 | CHECK_ERROR_CLOSE (mbox, mpd, EACCES); |
480 | } | 490 | } |
481 | 491 | ||
482 | url_get_auth (mbox->url, auth, 64, &n); | 492 | if (mbox->authority == NULL) |
483 | if (n == 0 || strcasecmp (auth, "*") == 0) | ||
484 | { | ||
485 | authority_create (&(mbox->authority), mbox->ticket, mbox); | ||
486 | authority_set_authenticate (mbox->authority, pop_user, mbox); | ||
487 | } | ||
488 | else if (strcasecmp (auth, "+apop") == 0) | ||
489 | { | 493 | { |
490 | /* Not supported. */ | 494 | url_get_auth (mbox->url, auth, 64, &n); |
491 | } | 495 | if (n == 0 || strcasecmp (auth, "*") == 0) |
492 | else | 496 | { |
493 | { | 497 | authority_create (&(mbox->authority), mbox->ticket, mbox); |
494 | /* What can do flag an error ? */ | 498 | authority_set_authenticate (mbox->authority, pop_user, mbox); |
499 | } | ||
500 | else if (strcasecmp (auth, "+apop") == 0) | ||
501 | { | ||
502 | /* Not supported. */ | ||
503 | } | ||
504 | else | ||
505 | { | ||
506 | /* What can we do ? flag an error ? */ | ||
507 | } | ||
495 | } | 508 | } |
496 | mpd->state = POP_AUTH; | 509 | mpd->state = POP_AUTH; |
497 | } | 510 | } | ... | ... |
... | @@ -576,9 +576,12 @@ void mime_destroy(mime_t *pmime) | ... | @@ -576,9 +576,12 @@ void mime_destroy(mime_t *pmime) |
576 | if ( mime->mtp_parts != NULL ) { | 576 | if ( mime->mtp_parts != NULL ) { |
577 | for ( i = 0; i < mime->nmtp_parts; i++ ) { | 577 | for ( i = 0; i < mime->nmtp_parts; i++ ) { |
578 | mime_part = mime->mtp_parts[i]; | 578 | mime_part = mime->mtp_parts[i]; |
579 | if ( mime_part->msg ) | 579 | if ( mime_part->msg ) { |
580 | message_destroy(&mime_part->msg, mime_part); | 580 | message_destroy(&mime_part->msg, mime_part); |
581 | free (mime_part); | ||
582 | } | ||
581 | } | 583 | } |
584 | free (mime->mtp_parts); | ||
582 | } | 585 | } |
583 | if ( mime->content_type ) | 586 | if ( mime->content_type ) |
584 | free(mime->content_type); | 587 | free(mime->content_type); | ... | ... |
... | @@ -134,13 +134,17 @@ observable_destroy (observable_t *pobservable, void *owner) | ... | @@ -134,13 +134,17 @@ observable_destroy (observable_t *pobservable, void *owner) |
134 | int status = iterator_create (&iterator, observable->list); | 134 | int status = iterator_create (&iterator, observable->list); |
135 | if (status == 0) | 135 | if (status == 0) |
136 | { | 136 | { |
137 | observer_t observer = NULL; | 137 | event_t event = NULL; |
138 | for (iterator_first (iterator); !iterator_is_done (iterator); | 138 | for (iterator_first (iterator); !iterator_is_done (iterator); |
139 | iterator_next (iterator)) | 139 | iterator_next (iterator)) |
140 | { | 140 | { |
141 | iterator_current (iterator, (void **)&observer); | 141 | event = NULL; |
142 | if (observer != NULL) | 142 | iterator_current (iterator, (void **)&event); |
143 | observer_destroy (&observer, NULL); | 143 | if (event != NULL) |
144 | { | ||
145 | observer_destroy (&(event->observer), NULL); | ||
146 | free (event); | ||
147 | } | ||
144 | } | 148 | } |
145 | } | 149 | } |
146 | list_destroy (&((*pobservable)->list)); | 150 | list_destroy (&((*pobservable)->list)); |
... | @@ -157,11 +161,17 @@ observable_get_owner (observable_t observable) | ... | @@ -157,11 +161,17 @@ observable_get_owner (observable_t observable) |
157 | } | 161 | } |
158 | 162 | ||
159 | int | 163 | int |
160 | observable_attach (observable_t observable, observer_t observer) | 164 | observable_attach (observable_t observable, size_t type, observer_t observer) |
161 | { | 165 | { |
166 | event_t event; | ||
162 | if (observable == NULL || observer == NULL) | 167 | if (observable == NULL || observer == NULL) |
163 | return EINVAL; | 168 | return EINVAL; |
164 | return list_append (observable->list, observer); | 169 | event = calloc (1, sizeof (*event)); |
170 | if (event == NULL) | ||
171 | return ENOMEM; | ||
172 | event->type = type; | ||
173 | event->observer = observer; | ||
174 | return list_append (observable->list, event); | ||
165 | } | 175 | } |
166 | 176 | ||
167 | int | 177 | int |
... | @@ -170,7 +180,7 @@ observable_detach (observable_t observable, observer_t observer) | ... | @@ -170,7 +180,7 @@ observable_detach (observable_t observable, observer_t observer) |
170 | iterator_t iterator; | 180 | iterator_t iterator; |
171 | int status; | 181 | int status; |
172 | int found = 0; | 182 | int found = 0; |
173 | observer_t current; | 183 | event_t event = NULL; |
174 | if (observable == NULL ||observer == NULL) | 184 | if (observable == NULL ||observer == NULL) |
175 | return EINVAL; | 185 | return EINVAL; |
176 | status = iterator_create (&iterator, observable->list); | 186 | status = iterator_create (&iterator, observable->list); |
... | @@ -179,22 +189,30 @@ observable_detach (observable_t observable, observer_t observer) | ... | @@ -179,22 +189,30 @@ observable_detach (observable_t observable, observer_t observer) |
179 | for (iterator_first (iterator); !iterator_is_done (iterator); | 189 | for (iterator_first (iterator); !iterator_is_done (iterator); |
180 | iterator_next (iterator)) | 190 | iterator_next (iterator)) |
181 | { | 191 | { |
182 | iterator_current (iterator, (void **)¤t); | 192 | event = NULL; |
183 | if ((int)(current) == (int)observer) | 193 | iterator_current (iterator, (void **)&event); |
194 | if (event && (int)(event->observer) == (int)observer) | ||
184 | { | 195 | { |
185 | found = 1; | 196 | found = 1; |
186 | break; | 197 | break; |
187 | } | 198 | } |
188 | } | 199 | } |
189 | iterator_destroy (&iterator); | 200 | iterator_destroy (&iterator); |
190 | return (found) ? list_remove (observable->list, observer) : ENOENT; | 201 | if (found) |
202 | { | ||
203 | status = list_remove (observable->list, event); | ||
204 | free (event); | ||
205 | } | ||
206 | else | ||
207 | status = ENOENT; | ||
208 | return status; | ||
191 | } | 209 | } |
192 | 210 | ||
193 | int | 211 | int |
194 | observable_notify (observable_t observable, int type) | 212 | observable_notify (observable_t observable, int type) |
195 | { | 213 | { |
196 | iterator_t iterator; | 214 | iterator_t iterator; |
197 | observer_t observer = NULL; | 215 | event_t event = NULL; |
198 | int status = 0; | 216 | int status = 0; |
199 | if (observable == NULL) | 217 | if (observable == NULL) |
200 | return EINVAL; | 218 | return EINVAL; |
... | @@ -204,11 +222,11 @@ observable_notify (observable_t observable, int type) | ... | @@ -204,11 +222,11 @@ observable_notify (observable_t observable, int type) |
204 | for (iterator_first (iterator); !iterator_is_done (iterator); | 222 | for (iterator_first (iterator); !iterator_is_done (iterator); |
205 | iterator_next (iterator)) | 223 | iterator_next (iterator)) |
206 | { | 224 | { |
207 | iterator_current (iterator, (void **)&observer); | 225 | event = NULL; |
208 | if (observer) | 226 | iterator_current (iterator, (void **)&event); |
227 | if (event && event->type & type) | ||
209 | { | 228 | { |
210 | status |= observer_action (observer, type); | 229 | status |= observer_action (event->observer, type); |
211 | observer = NULL; | ||
212 | } | 230 | } |
213 | } | 231 | } |
214 | iterator_destroy (&iterator); | 232 | iterator_destroy (&iterator); | ... | ... |
... | @@ -63,29 +63,41 @@ record_is_scheme (record_t record, const char *scheme) | ... | @@ -63,29 +63,41 @@ record_is_scheme (record_t record, const char *scheme) |
63 | int | 63 | int |
64 | record_get_mailbox (record_t record, mailbox_entry_t *pmbox) | 64 | record_get_mailbox (record_t record, mailbox_entry_t *pmbox) |
65 | { | 65 | { |
66 | if (record == NULL) | 66 | if (record == NULL || pmbox == NULL) |
67 | return EINVAL; | 67 | return EINVAL; |
68 | 68 | ||
69 | /* Overload. */ | 69 | /* Overload. */ |
70 | if (record->_get_mailbox) | 70 | if (record->_get_mailbox) |
71 | return record->_get_mailbox (record, pmbox); | 71 | return record->_get_mailbox (record, pmbox); |
72 | 72 | ||
73 | if (pmbox) | 73 | *pmbox = record->mailbox; |
74 | *pmbox = record->mailbox; | ||
75 | return 0; | 74 | return 0; |
76 | } | 75 | } |
77 | 76 | ||
78 | int | 77 | int |
79 | record_get_mailer (record_t record, mailer_entry_t *pml) | 78 | record_get_mailer (record_t record, mailer_entry_t *pml) |
80 | { | 79 | { |
81 | if (record == NULL) | 80 | if (record == NULL || pml == NULL) |
82 | return EINVAL; | 81 | return EINVAL; |
83 | 82 | ||
84 | /* Overload. */ | 83 | /* Overload. */ |
85 | if (record->_get_mailer) | 84 | if (record->_get_mailer) |
86 | return record->_get_mailer (record, pml); | 85 | return record->_get_mailer (record, pml); |
87 | 86 | ||
88 | if (pml) | 87 | *pml = record->mailer; |
89 | *pml = record->mailer; | 88 | return 0; |
89 | } | ||
90 | |||
91 | int | ||
92 | record_get_folder (record_t record, folder_entry_t *pfolder) | ||
93 | { | ||
94 | if (record == NULL || pfolder == NULL) | ||
95 | return EINVAL; | ||
96 | |||
97 | /* Overload. */ | ||
98 | if (record->_get_folder) | ||
99 | return record->_get_folder (record, pfolder); | ||
100 | |||
101 | *pfolder = record->folder; | ||
90 | return 0; | 102 | return 0; |
91 | } | 103 | } | ... | ... |
... | @@ -43,11 +43,13 @@ static struct _record _sendmail_record = | ... | @@ -43,11 +43,13 @@ static struct _record _sendmail_record = |
43 | MU_SENDMAIL_SCHEME, | 43 | MU_SENDMAIL_SCHEME, |
44 | NULL, /* Mailbox entry. */ | 44 | NULL, /* Mailbox entry. */ |
45 | &_sendmail_entry, /* Mailer entry. */ | 45 | &_sendmail_entry, /* Mailer entry. */ |
46 | NULL, /* Folder entry. */ | ||
46 | 0, /* Not malloc()ed. */ | 47 | 0, /* Not malloc()ed. */ |
47 | NULL, /* No need for an owner. */ | 48 | NULL, /* No need for an owner. */ |
48 | NULL, /* is_scheme method. */ | 49 | NULL, /* is_scheme method. */ |
49 | NULL, /* get_mailbox method. */ | 50 | NULL, /* get_mailbox method. */ |
50 | NULL /* get_mailer method. */ | 51 | NULL, /* get_mailer method. */ |
52 | NULL /* get_folder method. */ | ||
51 | }; | 53 | }; |
52 | 54 | ||
53 | /* We export two functions: url parsing and the initialisation of | 55 | /* We export two functions: url parsing and the initialisation of | ... | ... |
... | @@ -45,11 +45,13 @@ static struct _record _smtp_record = | ... | @@ -45,11 +45,13 @@ static struct _record _smtp_record = |
45 | MU_SMTP_SCHEME, | 45 | MU_SMTP_SCHEME, |
46 | NULL, /* Mailbox entry. */ | 46 | NULL, /* Mailbox entry. */ |
47 | &_smtp_entry, /* Mailer entry. */ | 47 | &_smtp_entry, /* Mailer entry. */ |
48 | NULL, /* Mailer entry. */ | ||
48 | 0, /* Not malloc()ed. */ | 49 | 0, /* Not malloc()ed. */ |
49 | NULL, /* No need for an owner. */ | 50 | NULL, /* No need for an owner. */ |
50 | NULL, /* is_scheme method. */ | 51 | NULL, /* is_scheme method. */ |
51 | NULL, /* get_mailbox method. */ | 52 | NULL, /* get_mailbox method. */ |
52 | NULL /* get_mailer method. */ | 53 | NULL, /* get_mailer method. */ |
54 | NULL /* get_folder method. */ | ||
53 | }; | 55 | }; |
54 | 56 | ||
55 | /* We export two functions: url parsing and the initialisation of | 57 | /* We export two functions: url parsing and the initialisation of |
... | @@ -287,8 +289,6 @@ smtp_open (mailer_t mailer, int flags) | ... | @@ -287,8 +289,6 @@ smtp_open (mailer_t mailer, int flags) |
287 | } | 289 | } |
288 | smtp->ptr = smtp->buffer; | 290 | smtp->ptr = smtp->buffer; |
289 | } | 291 | } |
290 | status = bio_create (&(smtp->bio), mailer->stream); | ||
291 | CHECK_ERROR (smtp, status); | ||
292 | 292 | ||
293 | /* Create a TCP stack if one is not given. */ | 293 | /* Create a TCP stack if one is not given. */ |
294 | if (mailer->stream == NULL) | 294 | if (mailer->stream == NULL) |
... | @@ -296,6 +296,8 @@ smtp_open (mailer_t mailer, int flags) | ... | @@ -296,6 +296,8 @@ smtp_open (mailer_t mailer, int flags) |
296 | status = tcp_stream_create (&(mailer->stream)); | 296 | status = tcp_stream_create (&(mailer->stream)); |
297 | CHECK_ERROR (smtp, status); | 297 | CHECK_ERROR (smtp, status); |
298 | } | 298 | } |
299 | status = bio_create (&(smtp->bio), mailer->stream); | ||
300 | CHECK_ERROR (smtp, status); | ||
299 | smtp->state = SMTP_OPEN; | 301 | smtp->state = SMTP_OPEN; |
300 | 302 | ||
301 | case SMTP_OPEN: | 303 | case SMTP_OPEN: | ... | ... |
... | @@ -44,6 +44,7 @@ url_destroy (url_t *purl) | ... | @@ -44,6 +44,7 @@ url_destroy (url_t *purl) |
44 | if (purl && *purl) | 44 | if (purl && *purl) |
45 | { | 45 | { |
46 | url_t url = (*purl); | 46 | url_t url = (*purl); |
47 | |||
47 | if (url->_destroy) | 48 | if (url->_destroy) |
48 | url->_destroy (url); | 49 | url->_destroy (url); |
49 | 50 | ||
... | @@ -59,9 +60,18 @@ url_destroy (url_t *purl) | ... | @@ -59,9 +60,18 @@ url_destroy (url_t *purl) |
59 | if (url->passwd) | 60 | if (url->passwd) |
60 | free (url->passwd); | 61 | free (url->passwd); |
61 | 62 | ||
63 | if (url->auth) | ||
64 | free (url->auth); | ||
65 | |||
62 | if (url->host) | 66 | if (url->host) |
63 | free (url->host); | 67 | free (url->host); |
64 | 68 | ||
69 | if (url->path) | ||
70 | free (url->path); | ||
71 | |||
72 | if (url->query) | ||
73 | free (url->query); | ||
74 | |||
65 | free (url); | 75 | free (url); |
66 | 76 | ||
67 | *purl = NULL; | 77 | *purl = NULL; | ... | ... |
-
Please register or sign in to post a comment