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).
Showing
29 changed files
with
347 additions
and
573 deletions
1 | 2001-10-14 Alain Magloire | ||
2 | |||
3 | The code for property.c has been change for a more simple approach, | ||
4 | it is the same approach as in mail/util.c(environment) settings. | ||
5 | The old code was simply overkill, property_t was seldomly use | ||
6 | if at all and no need for heavy hash table and all that jazz. | ||
7 | |||
8 | * mailbox/property.c: New code, the same as mail/util.c | ||
9 | environment. | ||
10 | * mailbox/mbx_mbox.c (_mbx_init): Remove property_add_defaults() etc .. | ||
11 | no longer in use in the initialisation code. | ||
12 | * mailbox/mbx_imap.c: Likewised | ||
13 | * mailbox/mbx_pop.c: Likewised | ||
14 | * mailbox/mbx_mh.c: Likewised | ||
15 | * mailbox/header.c: Remove property code. | ||
16 | * mailbox/body.c: Remove property code. | ||
17 | * mailbox/message.c: Remove property code. | ||
18 | * mailbox/filter.c: Change the code according to the new property_t. | ||
19 | * mailbox/filter_rfc822.c: Change the code according to the new | ||
20 | property_t. | ||
21 | * include/mailutils/header.h: Remove property. | ||
22 | * include/mailutils/body.h: Remove property. | ||
23 | * include/mailutils/message.h: Remove property. | ||
24 | * include/mailutils/property.h: Remove property_add_defaults() | ||
25 | property_set_valued () takes one more argument for overwrite. | ||
26 | * mailbox/include/header0.hy: Remove property field. | ||
27 | * mailbox/include/body0.hy: Remove property field. | ||
28 | * mailbox/include/message0.hy: Remove property field. | ||
29 | * mailbox/mailbox.c(mailbox_get_property mailbox_set_property): | ||
30 | Changed Property code. | ||
31 | * mailbox/mailer.c(mailer_set_property mailer_get_property): | ||
32 | Changed Property code. | ||
33 | |||
34 | * mailbox/folder_imap.c (imap_search imap_expunge imap_status): Stubs | ||
35 | Search is not implemented yet, STATUS neither and EXPUNGE is not used. | ||
36 | |||
37 | * mailbox/list.c: Rename variable index to indx to shutup | ||
38 | gcc whos confusing with index() when warning level was high. | ||
39 | * mailbox/md5-rsa.c: Likewised. | ||
40 | |||
41 | * mailbox/mailbox.c (mailbox_get_debug mailbox_set_debug): | ||
42 | The debug object was being set on the folder not the mailbox. | ||
43 | |||
44 | * mailbox/mbx_imap.c (imap_messages_count): Attempt to reconnect | ||
45 | if the connection timeout. Is this wise ? | ||
46 | (imap_scan0): Move gut of imap_scan() code tho here. | ||
47 | (imap_scan): Stub calling imap_scan0() with notification enable. | ||
48 | (imap_expunge): After CLOSE, call imap_scan0() wiht notification | ||
49 | disable. | ||
50 | |||
51 | Memory leak in parse822, this was a real pain to trace, because | ||
52 | of the recursive nature of the algorithm. Sam should buy me | ||
53 | a beer for this. | ||
54 | |||
55 | * mailbox/parse822.c: Use more assert to catch errors. | ||
56 | (parse822_group): phrase was not free() in case of failure. | ||
57 | (parse822_mail_box): Dead if branch remove and free phrase. | ||
58 | (parse822_route): accumulator was not being freed. | ||
59 | (parse822_local_part): Move down st_free(more). | ||
60 | (parse822_domain): Move down st_free(more). | ||
61 | |||
62 | |||
1 | 2001-10-14 Sergey Poznyakoff | 63 | 2001-10-14 Sergey Poznyakoff |
2 | 64 | ||
3 | Small fixes: | 65 | Small fixes: | ... | ... |
... | @@ -19,7 +19,6 @@ | ... | @@ -19,7 +19,6 @@ |
19 | #define _MAILUTILS_BODY_H | 19 | #define _MAILUTILS_BODY_H |
20 | 20 | ||
21 | #include <sys/types.h> | 21 | #include <sys/types.h> |
22 | #include <mailutils/property.h> | ||
23 | #include <mailutils/stream.h> | 22 | #include <mailutils/stream.h> |
24 | 23 | ||
25 | #ifndef __P | 24 | #ifndef __P |
... | @@ -47,9 +46,6 @@ extern int body_clear_modified __P ((body_t)); | ... | @@ -47,9 +46,6 @@ extern int body_clear_modified __P ((body_t)); |
47 | extern int body_get_stream __P ((body_t, stream_t *)); | 46 | extern int body_get_stream __P ((body_t, stream_t *)); |
48 | extern int body_set_stream __P ((body_t, stream_t, void *owner)); | 47 | extern int body_set_stream __P ((body_t, stream_t, void *owner)); |
49 | 48 | ||
50 | extern int body_get_property __P ((body_t, property_t *)); | ||
51 | extern int body_set_property __P ((body_t, property_t, void *)); | ||
52 | |||
53 | extern int body_get_filename __P ((body_t, char *, size_t, size_t *)); | 49 | extern int body_get_filename __P ((body_t, char *, size_t, size_t *)); |
54 | 50 | ||
55 | extern int body_size __P ((body_t, size_t*)); | 51 | extern int body_size __P ((body_t, size_t*)); | ... | ... |
... | @@ -20,7 +20,6 @@ | ... | @@ -20,7 +20,6 @@ |
20 | 20 | ||
21 | #include <sys/types.h> | 21 | #include <sys/types.h> |
22 | #include <mailutils/stream.h> | 22 | #include <mailutils/stream.h> |
23 | #include <mailutils/property.h> | ||
24 | 23 | ||
25 | #ifndef __P | 24 | #ifndef __P |
26 | #ifdef __STDC__ | 25 | #ifdef __STDC__ |
... | @@ -86,9 +85,6 @@ extern void *header_get_owner __P ((header_t)); | ... | @@ -86,9 +85,6 @@ extern void *header_get_owner __P ((header_t)); |
86 | extern int header_is_modified __P ((header_t)); | 85 | extern int header_is_modified __P ((header_t)); |
87 | extern int header_clear_modified __P ((header_t)); | 86 | extern int header_clear_modified __P ((header_t)); |
88 | 87 | ||
89 | extern int header_get_property __P ((header_t, property_t *)); | ||
90 | extern int header_set_property __P ((header_t, property_t, void *)); | ||
91 | |||
92 | extern int header_set_value __P ((header_t, const char *, | 88 | extern int header_set_value __P ((header_t, const char *, |
93 | const char *, int)); | 89 | const char *, int)); |
94 | extern int header_set_set_value __P ((header_t, | 90 | extern int header_set_set_value __P ((header_t, | ... | ... |
... | @@ -30,7 +30,6 @@ typedef struct _message *message_t; | ... | @@ -30,7 +30,6 @@ typedef struct _message *message_t; |
30 | #include <mailutils/stream.h> | 30 | #include <mailutils/stream.h> |
31 | #include <mailutils/observer.h> | 31 | #include <mailutils/observer.h> |
32 | #include <mailutils/attribute.h> | 32 | #include <mailutils/attribute.h> |
33 | #include <mailutils/property.h> | ||
34 | #include <mailutils/mailbox.h> | 33 | #include <mailutils/mailbox.h> |
35 | 34 | ||
36 | #ifndef __P | 35 | #ifndef __P |
... | @@ -72,8 +71,6 @@ extern int message_set_body __P ((message_t, body_t, void *)); | ... | @@ -72,8 +71,6 @@ extern int message_set_body __P ((message_t, body_t, void *)); |
72 | extern int message_get_stream __P ((message_t, stream_t *)); | 71 | extern int message_get_stream __P ((message_t, stream_t *)); |
73 | extern int message_set_stream __P ((message_t, stream_t, void *)); | 72 | extern int message_set_stream __P ((message_t, stream_t, void *)); |
74 | 73 | ||
75 | extern int message_get_property __P ((message_t, property_t *)); | ||
76 | extern int message_set_property __P ((message_t, property_t, void *)); | ||
77 | extern int message_get_attribute __P ((message_t, attribute_t *)); | 74 | extern int message_get_attribute __P ((message_t, attribute_t *)); |
78 | extern int message_set_attribute __P ((message_t, attribute_t, void *)); | 75 | extern int message_set_attribute __P ((message_t, attribute_t, void *)); |
79 | 76 | ... | ... |
... | @@ -35,19 +35,14 @@ extern "C" { | ... | @@ -35,19 +35,14 @@ extern "C" { |
35 | struct _property; | 35 | struct _property; |
36 | typedef struct _property *property_t; | 36 | typedef struct _property *property_t; |
37 | 37 | ||
38 | extern int property_create __P ((property_t *, void *)); | 38 | extern int property_create __P ((property_t *, void *)); |
39 | extern void property_destroy __P ((property_t *, void *)); | 39 | extern void property_destroy __P ((property_t *, void *)); |
40 | extern void *property_get_owner __P ((property_t)); | 40 | extern void *property_get_owner __P ((property_t)); |
41 | 41 | ||
42 | extern int property_set_value __P ((property_t, const char *, const char *)); | 42 | extern int property_set_value __P ((property_t, const char *, |
43 | extern int property_get_value | 43 | const char *, int)); |
44 | __P ((property_t, const char *, char *, size_t, size_t *)); | 44 | extern int property_get_value __P ((property_t, const char *, char *, |
45 | 45 | size_t, size_t *)); | |
46 | extern int property_add_defaults | ||
47 | __P ((property_t, const char *, const char *, | ||
48 | int (*) __P ((property_t, const char *, const char *)), | ||
49 | int (*) __P ((property_t, const char *, char *, size_t, size_t *)), | ||
50 | void *)); | ||
51 | 46 | ||
52 | /* Helper functions. */ | 47 | /* Helper functions. */ |
53 | extern int property_set __P ((property_t, const char *)); | 48 | extern int property_set __P ((property_t, const char *)); | ... | ... |
... | @@ -81,9 +81,6 @@ body_destroy (body_t *pbody, void *owner) | ... | @@ -81,9 +81,6 @@ body_destroy (body_t *pbody, void *owner) |
81 | stream_destroy (&(body->fstream), NULL); | 81 | stream_destroy (&(body->fstream), NULL); |
82 | } | 82 | } |
83 | 83 | ||
84 | if (body->property) | ||
85 | property_destroy (&(body->property), body); | ||
86 | |||
87 | free (body); | 84 | free (body); |
88 | } | 85 | } |
89 | *pbody = NULL; | 86 | *pbody = NULL; |
... | @@ -113,33 +110,6 @@ body_clear_modified (body_t body) | ... | @@ -113,33 +110,6 @@ body_clear_modified (body_t body) |
113 | } | 110 | } |
114 | 111 | ||
115 | int | 112 | int |
116 | body_set_property (body_t body, property_t property, void *owner) | ||
117 | { | ||
118 | if (body == NULL) | ||
119 | return EINVAL; | ||
120 | if (body->owner != owner) | ||
121 | return EACCES; | ||
122 | property_destroy (&(body->property), body); | ||
123 | body->property = property; | ||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | int | ||
128 | body_get_property (body_t body, property_t *pproperty) | ||
129 | { | ||
130 | if (body == NULL || pproperty == NULL) | ||
131 | return EINVAL; | ||
132 | if (body->property == NULL) | ||
133 | { | ||
134 | int status = property_create (&(body->property), body); | ||
135 | if (status != 0) | ||
136 | return status; | ||
137 | } | ||
138 | *pproperty = body->property; | ||
139 | return 0; | ||
140 | } | ||
141 | |||
142 | int | ||
143 | body_get_filename (body_t body, char *filename, size_t len, size_t *pn) | 113 | body_get_filename (body_t body, char *filename, size_t len, size_t *pn) |
144 | { | 114 | { |
145 | int n = 0; | 115 | int n = 0; | ... | ... |
... | @@ -122,29 +122,6 @@ filter_close (stream_t stream) | ... | @@ -122,29 +122,6 @@ filter_close (stream_t stream) |
122 | return stream_close (filter->stream); | 122 | return stream_close (filter->stream); |
123 | } | 123 | } |
124 | 124 | ||
125 | static int | ||
126 | filter_property (property_t property, const char *key, const char *value) | ||
127 | { | ||
128 | filter_t filter = property_get_owner (property); | ||
129 | (void)key; | ||
130 | if (value) | ||
131 | { | ||
132 | if (strcasecmp (value, "READ") == 0) | ||
133 | { | ||
134 | filter->direction = MU_STREAM_READ; | ||
135 | } | ||
136 | else if (strcasecmp (value, "WRITE") == 0) | ||
137 | { | ||
138 | filter->direction = MU_STREAM_WRITE; | ||
139 | } | ||
140 | else if (strcasecmp (value, "RDWR") == 0) | ||
141 | { | ||
142 | filter->direction = MU_STREAM_RDWR; | ||
143 | } | ||
144 | } | ||
145 | return 0; | ||
146 | } | ||
147 | |||
148 | /* NOTE: We will leak here since the monitor of the filter will never | 125 | /* NOTE: We will leak here since the monitor of the filter will never |
149 | be release. That's ok we can leave with this, it's only done once. */ | 126 | be release. That's ok we can leave with this, it's only done once. */ |
150 | static list_t filter_list; | 127 | static list_t filter_list; |
... | @@ -241,12 +218,11 @@ filter_create (stream_t *pstream, stream_t stream, const char *name, | ... | @@ -241,12 +218,11 @@ filter_create (stream_t *pstream, stream_t stream, const char *name, |
241 | free (filter); | 218 | free (filter); |
242 | return status; | 219 | return status; |
243 | } | 220 | } |
244 | property_add_defaults (filter->property, "DIRECTION", | 221 | property_set_value (filter->property, "DIRECTION", |
245 | ((filter->direction == MU_STREAM_WRITE) ? "WRITE": | 222 | ((filter->direction == MU_STREAM_WRITE) ? "WRITE": |
246 | (filter->direction == MU_STREAM_RDWR) ? "RDWR" : | 223 | (filter->direction == MU_STREAM_RDWR) ? "RDWR" : |
247 | "READ"), filter_property, NULL, filter); | 224 | "READ"), 1); |
248 | property_add_defaults (filter->property, "NAME", filter_record->name, | 225 | property_set_value (filter->property, "TYPE", filter_record->name, 1); |
249 | NULL, NULL, filter); | ||
250 | stream_set_property (*pstream, filter->property, filter); | 226 | stream_set_property (*pstream, filter->property, filter); |
251 | 227 | ||
252 | if (f_init != NULL) | 228 | if (f_init != NULL) | ... | ... |
... | @@ -27,7 +27,6 @@ | ... | @@ -27,7 +27,6 @@ |
27 | #include <mailutils/property.h> | 27 | #include <mailutils/property.h> |
28 | #include <filter0.h> | 28 | #include <filter0.h> |
29 | 29 | ||
30 | static int rfc822_property __P ((property_t, const char *, const char *)); | ||
31 | static int rfc822_init __P ((filter_t)); | 30 | static int rfc822_init __P ((filter_t)); |
32 | static void rfc822_destroy __P ((filter_t)); | 31 | static void rfc822_destroy __P ((filter_t)); |
33 | static int rfc822_read __P ((filter_t, char *, size_t, off_t, size_t *)); | 32 | static int rfc822_read __P ((filter_t, char *, size_t, off_t, size_t *)); |
... | @@ -55,16 +54,6 @@ static struct _filter_record _rfc822_filter = | ... | @@ -55,16 +54,6 @@ static struct _filter_record _rfc822_filter = |
55 | filter_record_t rfc822_filter = &_rfc822_filter; | 54 | filter_record_t rfc822_filter = &_rfc822_filter; |
56 | 55 | ||
57 | static int | 56 | static int |
58 | rfc822_property (property_t property, const char *key, const char *value) | ||
59 | { | ||
60 | filter_t filter = property_get_owner (property); | ||
61 | struct rfc822 *rfc822 = filter->data; | ||
62 | (void)key; | ||
63 | rfc822->lines = strtoul (value, NULL, 10); | ||
64 | return 0; | ||
65 | } | ||
66 | |||
67 | static int | ||
68 | rfc822_init (filter_t filter) | 57 | rfc822_init (filter_t filter) |
69 | { | 58 | { |
70 | property_t property; | 59 | property_t property; |
... | @@ -79,8 +68,7 @@ rfc822_init (filter_t filter) | ... | @@ -79,8 +68,7 @@ rfc822_init (filter_t filter) |
79 | 68 | ||
80 | /* We are interested in this property. */ | 69 | /* We are interested in this property. */ |
81 | if ((status = stream_get_property (filter->filter_stream, &property) != 0) | 70 | if ((status = stream_get_property (filter->filter_stream, &property) != 0) |
82 | || (status = property_add_defaults (property, "LINES", "0", | 71 | || (status = property_set_value (property, "LINES", "0", 1)) != 0) |
83 | rfc822_property, NULL, filter)) != 0) | ||
84 | { | 72 | { |
85 | free (filter->data); | 73 | free (filter->data); |
86 | filter->data = NULL; | 74 | filter->data = NULL; | ... | ... |
... | @@ -59,43 +59,46 @@ static struct _record _imap_record = | ... | @@ -59,43 +59,46 @@ static struct _record _imap_record = |
59 | record_t imap_record = &_imap_record; | 59 | record_t imap_record = &_imap_record; |
60 | 60 | ||
61 | #ifndef HAVE_STRTOK_R | 61 | #ifndef HAVE_STRTOK_R |
62 | char *strtok_r __P ((char *, const char *, char **)); | 62 | char *strtok_r __P ((char *, const char *, char **)); |
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | /* Concrete IMAP implementation. */ | 65 | /* Concrete folder_t IMAP implementation. */ |
66 | static int folder_imap_open __P ((folder_t, int)); | 66 | static int folder_imap_open __P ((folder_t, int)); |
67 | static int folder_imap_create __P ((folder_t)); | 67 | static int folder_imap_create __P ((folder_t)); |
68 | static int folder_imap_close __P ((folder_t)); | 68 | static int folder_imap_close __P ((folder_t)); |
69 | static void folder_imap_destroy __P ((folder_t)); | 69 | static void folder_imap_destroy __P ((folder_t)); |
70 | static int folder_imap_delete __P ((folder_t, const char *)); | 70 | static int folder_imap_delete __P ((folder_t, const char *)); |
71 | static int folder_imap_list __P ((folder_t, const char *, const char *, | 71 | static int folder_imap_list __P ((folder_t, const char *, const char *, |
72 | struct folder_list *)); | 72 | struct folder_list *)); |
73 | static int folder_imap_lsub __P ((folder_t, const char *, const char *, | 73 | static int folder_imap_lsub __P ((folder_t, const char *, const char *, |
74 | struct folder_list *)); | 74 | struct folder_list *)); |
75 | static int folder_imap_rename __P ((folder_t, const char *, | 75 | static int folder_imap_rename __P ((folder_t, const char *, |
76 | const char *)); | 76 | const char *)); |
77 | static int folder_imap_subscribe __P ((folder_t, const char *)); | 77 | static int folder_imap_subscribe __P ((folder_t, const char *)); |
78 | static int folder_imap_unsubscribe __P ((folder_t, const char *)); | 78 | static int folder_imap_unsubscribe __P ((folder_t, const char *)); |
79 | 79 | ||
80 | /* Private */ | ||
81 | /* static int imap_readline (f_imap_t); */ | ||
82 | /* FETCH */ | 80 | /* FETCH */ |
83 | static int imap_fetch __P ((f_imap_t)); | 81 | static int imap_fetch __P ((f_imap_t)); |
84 | static int imap_rfc822 __P ((f_imap_t, char **)); | 82 | static int imap_rfc822 __P ((f_imap_t, char **)); |
85 | static int imap_rfc822_size __P ((f_imap_t, char **)); | 83 | static int imap_rfc822_size __P ((f_imap_t, char **)); |
86 | static int imap_rfc822_header __P ((f_imap_t, char **)); | 84 | static int imap_rfc822_header __P ((f_imap_t, char **)); |
87 | static int imap_rfc822_text __P ((f_imap_t, char **)); | 85 | static int imap_rfc822_text __P ((f_imap_t, char **)); |
88 | static int imap_flags __P ((f_imap_t, char **)); | 86 | static int imap_flags __P ((f_imap_t, char **)); |
89 | static int imap_bodystructure __P ((f_imap_t, char **)); | 87 | static int imap_bodystructure __P ((f_imap_t, char **)); |
90 | static int imap_body __P ((f_imap_t, char **)); | 88 | static int imap_body __P ((f_imap_t, char **)); |
91 | static int imap_uid __P ((f_imap_t, char **)); | 89 | static int imap_internaldate __P ((f_imap_t, char **)); |
90 | |||
91 | static int imap_uid __P ((f_imap_t, char **)); | ||
92 | static int imap_status __P ((f_imap_t)); | ||
93 | static int imap_expunge __P ((f_imap_t, unsigned int)); | ||
94 | static int imap_search __P ((f_imap_t)); | ||
92 | 95 | ||
93 | /* String. */ | 96 | /* String. */ |
94 | static int imap_literal_string __P ((f_imap_t, char **)); | 97 | static int imap_literal_string __P ((f_imap_t, char **)); |
95 | static int imap_string __P ((f_imap_t, char **)); | 98 | static int imap_string __P ((f_imap_t, char **)); |
96 | static int imap_quoted_string __P ((f_imap_t, char **)); | 99 | static int imap_quoted_string __P ((f_imap_t, char **)); |
97 | 100 | ||
98 | static int imap_token __P ((char *, size_t, char **)); | 101 | static int imap_token __P ((char *, size_t, char **)); |
99 | 102 | ||
100 | /* Initialize the concrete IMAP mailbox: overload the folder functions */ | 103 | /* Initialize the concrete IMAP mailbox: overload the folder functions */ |
101 | int | 104 | int |
... | @@ -486,7 +489,7 @@ folder_imap_delete (folder_t folder, const char *name) | ... | @@ -486,7 +489,7 @@ folder_imap_delete (folder_t folder, const char *name) |
486 | return status; | 489 | return status; |
487 | } | 490 | } |
488 | 491 | ||
489 | /* Since the mailutils API does not offer recursive listing. There is no need | 492 | /* Since mailutils API does not offer recursive listing. There is no need |
490 | to follow IMAP "bizarre" recursive rules. The use of '%' is sufficient. So | 493 | to follow IMAP "bizarre" recursive rules. The use of '%' is sufficient. So |
491 | the approach is everywhere there is a regex in the path we change that | 494 | the approach is everywhere there is a regex in the path we change that |
492 | branch for '%' and do the matching ourself with fnmatch(). */ | 495 | branch for '%' and do the matching ourself with fnmatch(). */ |
... | @@ -810,8 +813,6 @@ folder_imap_unsubscribe (folder_t folder, const char *name) | ... | @@ -810,8 +813,6 @@ folder_imap_unsubscribe (folder_t folder, const char *name) |
810 | return status; | 813 | return status; |
811 | } | 814 | } |
812 | 815 | ||
813 | /* Implementation. */ | ||
814 | |||
815 | /* A literal is a sequence of zero or more octets (including CR and LF), | 816 | /* A literal is a sequence of zero or more octets (including CR and LF), |
816 | prefix-quoted with an octet count in the form of an open brace ("{"), | 817 | prefix-quoted with an octet count in the form of an open brace ("{"), |
817 | the number of octets, close brace ("}"), and CRLF. The sequence is read | 818 | the number of octets, close brace ("}"), and CRLF. The sequence is read |
... | @@ -1563,6 +1564,32 @@ imap_fetch (f_imap_t f_imap) | ... | @@ -1563,6 +1564,32 @@ imap_fetch (f_imap_t f_imap) |
1563 | } | 1564 | } |
1564 | 1565 | ||
1565 | static int | 1566 | static int |
1567 | imap_search (f_imap_t f_imap) | ||
1568 | { | ||
1569 | (void)f_imap; | ||
1570 | /* Not implemented. No provision for this in the API, yet. */ | ||
1571 | return 0; | ||
1572 | } | ||
1573 | |||
1574 | static int | ||
1575 | imap_status (f_imap_t f_imap) | ||
1576 | { | ||
1577 | (void)f_imap; | ||
1578 | /* Not implemented. No provision for this in the API, yet. */ | ||
1579 | return 0; | ||
1580 | } | ||
1581 | |||
1582 | static int | ||
1583 | imap_expunge (f_imap_t f_imap, unsigned msgno) | ||
1584 | { | ||
1585 | (void)f_imap; (void)msgno; | ||
1586 | /* We should not have this, since do not send the expunge, but rather | ||
1587 | use SELECT/CLOSE. */ | ||
1588 | return 0; | ||
1589 | } | ||
1590 | |||
1591 | |||
1592 | static int | ||
1566 | imap_token (char *buf, size_t len, char **ptr) | 1593 | imap_token (char *buf, size_t len, char **ptr) |
1567 | { | 1594 | { |
1568 | char *start = *ptr; | 1595 | char *start = *ptr; |
... | @@ -1973,6 +2000,8 @@ imap_parse (f_imap_t f_imap) | ... | @@ -1973,6 +2000,8 @@ imap_parse (f_imap_t f_imap) |
1973 | } | 2000 | } |
1974 | else if (strcasecmp (remainder, "EXPUNGE") == 0) | 2001 | else if (strcasecmp (remainder, "EXPUNGE") == 0) |
1975 | { | 2002 | { |
2003 | unsigned int msgno = strtol (response, NULL, 10); | ||
2004 | status = imap_expunge (f_imap, msgno); | ||
1976 | } | 2005 | } |
1977 | else if (strncasecmp (remainder, "FETCH", 5) == 0) | 2006 | else if (strncasecmp (remainder, "FETCH", 5) == 0) |
1978 | { | 2007 | { |
... | @@ -1999,9 +2028,11 @@ imap_parse (f_imap_t f_imap) | ... | @@ -1999,9 +2028,11 @@ imap_parse (f_imap_t f_imap) |
1999 | } | 2028 | } |
2000 | else if (strcasecmp (response, "SEARCH") == 0) | 2029 | else if (strcasecmp (response, "SEARCH") == 0) |
2001 | { | 2030 | { |
2031 | status = imap_search (f_imap); | ||
2002 | } | 2032 | } |
2003 | else if (strcasecmp (response, "STATUS") == 0) | 2033 | else if (strcasecmp (response, "STATUS") == 0) |
2004 | { | 2034 | { |
2035 | status = imap_status (f_imap); | ||
2005 | } | 2036 | } |
2006 | else | 2037 | else |
2007 | { | 2038 | { |
... | @@ -2021,6 +2052,7 @@ imap_parse (f_imap_t f_imap) | ... | @@ -2021,6 +2052,7 @@ imap_parse (f_imap_t f_imap) |
2021 | done = 1; | 2052 | done = 1; |
2022 | if (strcasecmp (response, "OK") == 0) | 2053 | if (strcasecmp (response, "OK") == 0) |
2023 | { | 2054 | { |
2055 | /* Cool we are doing ok. */ | ||
2024 | } | 2056 | } |
2025 | else /* NO and BAD */ | 2057 | else /* NO and BAD */ |
2026 | { | 2058 | { | ... | ... |
... | @@ -100,9 +100,6 @@ header_destroy (header_t *ph, void *owner) | ... | @@ -100,9 +100,6 @@ header_destroy (header_t *ph, void *owner) |
100 | 100 | ||
101 | header_free_cache (header); | 101 | header_free_cache (header); |
102 | 102 | ||
103 | if (header->property) | ||
104 | property_destroy (&(header->property), header); | ||
105 | |||
106 | free (header); | 103 | free (header); |
107 | } | 104 | } |
108 | *ph = NULL; | 105 | *ph = NULL; |
... | @@ -781,33 +778,6 @@ header_size (header_t header, size_t *psize) | ... | @@ -781,33 +778,6 @@ header_size (header_t header, size_t *psize) |
781 | } | 778 | } |
782 | 779 | ||
783 | int | 780 | int |
784 | header_set_property (header_t header, property_t property, void *owner) | ||
785 | { | ||
786 | if (header == NULL) | ||
787 | return EINVAL; | ||
788 | if (header->owner != owner) | ||
789 | return EACCES; | ||
790 | property_destroy (&(header->property), header); | ||
791 | header->property = property; | ||
792 | return 0; | ||
793 | } | ||
794 | |||
795 | int | ||
796 | header_get_property (header_t header, property_t *pp) | ||
797 | { | ||
798 | if (header == NULL || pp == NULL) | ||
799 | return EINVAL; | ||
800 | if (header->property == NULL) | ||
801 | { | ||
802 | int status = property_create (&(header->property), header); | ||
803 | if (status != 0) | ||
804 | return status; | ||
805 | } | ||
806 | *pp = header->property; | ||
807 | return 0; | ||
808 | } | ||
809 | |||
810 | int | ||
811 | header_set_get_fvalue (header_t header, int (*_get_fvalue) | 781 | header_set_get_fvalue (header_t header, int (*_get_fvalue) |
812 | __P ((header_t, const char *, char *, size_t, | 782 | __P ((header_t, const char *, char *, size_t, |
813 | size_t *)), void *owner) | 783 | size_t *)), void *owner) | ... | ... |
... | @@ -46,7 +46,6 @@ struct _body | ... | @@ -46,7 +46,6 @@ struct _body |
46 | char *filename; | 46 | char *filename; |
47 | stream_t stream; | 47 | stream_t stream; |
48 | stream_t fstream; | 48 | stream_t fstream; |
49 | property_t property; | ||
50 | int flags; | 49 | int flags; |
51 | 50 | ||
52 | int (*_size) (body_t, size_t*); | 51 | int (*_size) (body_t, size_t*); | ... | ... |
... | @@ -64,7 +64,6 @@ struct _header | ... | @@ -64,7 +64,6 @@ struct _header |
64 | size_t fhdr_count; | 64 | size_t fhdr_count; |
65 | struct _hdr *fhdr; | 65 | struct _hdr *fhdr; |
66 | int flags; | 66 | int flags; |
67 | property_t property; | ||
68 | 67 | ||
69 | /* Streams. */ | 68 | /* Streams. */ |
70 | stream_t stream; | 69 | stream_t stream; | ... | ... |
... | @@ -40,14 +40,6 @@ extern "C" { | ... | @@ -40,14 +40,6 @@ extern "C" { |
40 | # endif | 40 | # endif |
41 | #endif /*__P */ | 41 | #endif /*__P */ |
42 | 42 | ||
43 | struct default_properties | ||
44 | { | ||
45 | char *key; | ||
46 | char *value; | ||
47 | int (*_set_value) __P ((property_t, const char *, const char *)); | ||
48 | int (*_get_value) __P ((property_t, const char *, char *, size_t, size_t *)); | ||
49 | }; | ||
50 | |||
51 | struct _mailbox | 43 | struct _mailbox |
52 | { | 44 | { |
53 | /* Data */ | 45 | /* Data */ |
... | @@ -56,8 +48,6 @@ struct _mailbox | ... | @@ -56,8 +48,6 @@ struct _mailbox |
56 | ticket_t ticket; | 48 | ticket_t ticket; |
57 | authority_t authority; | 49 | authority_t authority; |
58 | property_t property; | 50 | property_t property; |
59 | struct default_properties *properties; | ||
60 | size_t properties_count; | ||
61 | locker_t locker; | 51 | locker_t locker; |
62 | stream_t stream; | 52 | stream_t stream; |
63 | url_t url; | 53 | url_t url; |
... | @@ -72,25 +62,25 @@ struct _mailbox | ... | @@ -72,25 +62,25 @@ struct _mailbox |
72 | 62 | ||
73 | void (*_destroy) __P ((mailbox_t)); | 63 | void (*_destroy) __P ((mailbox_t)); |
74 | 64 | ||
75 | int (*_open) __P ((mailbox_t, int flag)); | 65 | int (*_open) __P ((mailbox_t, int)); |
76 | int (*_close) __P ((mailbox_t)); | 66 | int (*_close) __P ((mailbox_t)); |
77 | 67 | ||
78 | /* messages */ | 68 | /* messages */ |
79 | int (*_get_message) __P ((mailbox_t, size_t msgno, message_t *msg)); | 69 | int (*_get_message) __P ((mailbox_t, size_t, message_t *)); |
80 | int (*_append_message) __P ((mailbox_t, message_t msg)); | 70 | int (*_append_message) __P ((mailbox_t, message_t)); |
81 | int (*_messages_count) __P ((mailbox_t, size_t *num)); | 71 | int (*_messages_count) __P ((mailbox_t, size_t *)); |
82 | int (*_messages_recent) __P ((mailbox_t, size_t *num)); | 72 | int (*_messages_recent) __P ((mailbox_t, size_t *)); |
83 | int (*_message_unseen) __P ((mailbox_t, size_t *num)); | 73 | int (*_message_unseen) __P ((mailbox_t, size_t *)); |
84 | int (*_expunge) __P ((mailbox_t)); | 74 | int (*_expunge) __P ((mailbox_t)); |
85 | int (*_save_attributes) __P ((mailbox_t)); | 75 | int (*_save_attributes) __P ((mailbox_t)); |
86 | int (*_uidvalidity) __P ((mailbox_t, unsigned long *num)); | 76 | int (*_uidvalidity) __P ((mailbox_t, unsigned long *)); |
87 | int (*_uidnext) __P ((mailbox_t, size_t *num)); | 77 | int (*_uidnext) __P ((mailbox_t, size_t *)); |
88 | int (*_get_property) __P ((mailbox_t, property_t *num)); | 78 | int (*_get_property) __P ((mailbox_t, property_t *)); |
89 | 79 | ||
90 | int (*_scan) __P ((mailbox_t, size_t msgno, size_t *count)); | 80 | int (*_scan) __P ((mailbox_t, size_t, size_t *)); |
91 | int (*_is_updated) __P ((mailbox_t)); | 81 | int (*_is_updated) __P ((mailbox_t)); |
92 | 82 | ||
93 | int (*_get_size) __P ((mailbox_t, off_t *size)); | 83 | int (*_get_size) __P ((mailbox_t, off_t *)); |
94 | 84 | ||
95 | }; | 85 | }; |
96 | 86 | ... | ... |
... | @@ -53,14 +53,6 @@ extern "C" { | ... | @@ -53,14 +53,6 @@ extern "C" { |
53 | 53 | ||
54 | #define MAILER_LINE_BUF_SIZE 1000 | 54 | #define MAILER_LINE_BUF_SIZE 1000 |
55 | 55 | ||
56 | struct default_properties | ||
57 | { | ||
58 | char *key; | ||
59 | char *value; | ||
60 | int (*_set_value) __P ((property_t, const char *, const char *)); | ||
61 | int (*_get_value) __P ((property_t, const char *, char *, size_t, size_t *)); | ||
62 | }; | ||
63 | |||
64 | struct _mailer | 56 | struct _mailer |
65 | { | 57 | { |
66 | stream_t stream; | 58 | stream_t stream; |
... | @@ -70,7 +62,6 @@ struct _mailer | ... | @@ -70,7 +62,6 @@ struct _mailer |
70 | int flags; | 62 | int flags; |
71 | monitor_t monitor; | 63 | monitor_t monitor; |
72 | property_t property; | 64 | property_t property; |
73 | struct default_properties *properties; | ||
74 | size_t properties_count; | 65 | size_t properties_count; |
75 | 66 | ||
76 | /* Pointer to the specific mailer data. */ | 67 | /* Pointer to the specific mailer data. */ | ... | ... |
... | @@ -52,7 +52,6 @@ struct _message | ... | @@ -52,7 +52,6 @@ struct _message |
52 | 52 | ||
53 | int flags; | 53 | int flags; |
54 | stream_t stream; | 54 | stream_t stream; |
55 | property_t property; | ||
56 | attribute_t attribute; | 55 | attribute_t attribute; |
57 | monitor_t monitor; | 56 | monitor_t monitor; |
58 | mime_t mime; | 57 | mime_t mime; | ... | ... |
... | @@ -27,7 +27,7 @@ | ... | @@ -27,7 +27,7 @@ |
27 | #include <string.h> | 27 | #include <string.h> |
28 | 28 | ||
29 | #include <mailutils/property.h> | 29 | #include <mailutils/property.h> |
30 | #include <mailutils/iterator.h> | 30 | #include <mailutils/monitor.h> |
31 | 31 | ||
32 | #ifndef __P | 32 | #ifndef __P |
33 | #ifdef __STDC__ | 33 | #ifdef __STDC__ |
... | @@ -41,19 +41,19 @@ | ... | @@ -41,19 +41,19 @@ |
41 | extern "C" { | 41 | extern "C" { |
42 | #endif | 42 | #endif |
43 | 43 | ||
44 | struct property_data | 44 | struct property_item |
45 | { | 45 | { |
46 | size_t hash; | ||
47 | char *key; | 46 | char *key; |
48 | char *value; | 47 | char *value; |
49 | int (*_set_value) __P ((property_t, const char *, const char *)); | 48 | int set; |
50 | int (*_get_value) __P ((property_t, const char *, char *, size_t, size_t *)); | 49 | struct property_item *next; |
51 | }; | 50 | }; |
52 | 51 | ||
53 | struct _property | 52 | struct _property |
54 | { | 53 | { |
54 | struct property_item *items; | ||
55 | void *owner; | 55 | void *owner; |
56 | list_t list; | 56 | monitor_t lock; |
57 | }; | 57 | }; |
58 | 58 | ||
59 | #ifdef __cplusplus | 59 | #ifdef __cplusplus | ... | ... |
... | @@ -158,7 +158,7 @@ list_remove (list_t list, void *item) | ... | @@ -158,7 +158,7 @@ list_remove (list_t list, void *item) |
158 | Every time we iterate through the loop to get the data, an easy | 158 | Every time we iterate through the loop to get the data, an easy |
159 | fix is to a an index to the current. */ | 159 | fix is to a an index to the current. */ |
160 | int | 160 | int |
161 | list_get (list_t list, size_t index, void **pitem) | 161 | list_get (list_t list, size_t indx, void **pitem) |
162 | { | 162 | { |
163 | struct list_data *current; | 163 | struct list_data *current; |
164 | size_t count; | 164 | size_t count; |
... | @@ -169,7 +169,7 @@ list_get (list_t list, size_t index, void **pitem) | ... | @@ -169,7 +169,7 @@ list_get (list_t list, size_t index, void **pitem) |
169 | for (current = list->head.next, count = 0; current != &(list->head); | 169 | for (current = list->head.next, count = 0; current != &(list->head); |
170 | current = current->next, count++) | 170 | current = current->next, count++) |
171 | { | 171 | { |
172 | if (count == index) | 172 | if (count == indx) |
173 | { | 173 | { |
174 | *pitem = current->item; | 174 | *pitem = current->item; |
175 | status = 0; | 175 | status = 0; | ... | ... |
... | @@ -169,17 +169,6 @@ mailbox_destroy (mailbox_t *pmbox) | ... | @@ -169,17 +169,6 @@ mailbox_destroy (mailbox_t *pmbox) |
169 | if (mbox->folder) | 169 | if (mbox->folder) |
170 | folder_destroy (&(mbox->folder)); | 170 | folder_destroy (&(mbox->folder)); |
171 | 171 | ||
172 | if (mbox->properties) | ||
173 | { | ||
174 | size_t i; | ||
175 | for (i = 0; i < mbox->properties_count; i++) | ||
176 | { | ||
177 | if (mbox->properties[i].key) | ||
178 | free (mbox->properties[i].key); | ||
179 | } | ||
180 | free (mbox->properties); | ||
181 | } | ||
182 | |||
183 | if (mbox->property) | 172 | if (mbox->property) |
184 | property_destroy (&(mbox->property), mbox); | 173 | property_destroy (&(mbox->property), mbox); |
185 | 174 | ||
... | @@ -427,25 +416,9 @@ mailbox_get_property (mailbox_t mbox, property_t *pproperty) | ... | @@ -427,25 +416,9 @@ mailbox_get_property (mailbox_t mbox, property_t *pproperty) |
427 | return EINVAL; | 416 | return EINVAL; |
428 | if (mbox->property == NULL) | 417 | if (mbox->property == NULL) |
429 | { | 418 | { |
430 | size_t i; | ||
431 | int status = property_create (&(mbox->property), mbox); | 419 | int status = property_create (&(mbox->property), mbox); |
432 | if (status != 0) | 420 | if (status != 0) |
433 | return status; | 421 | return status; |
434 | /* Add the defaults. */ | ||
435 | for (i = 0; i < mbox->properties_count; i++) | ||
436 | { | ||
437 | status = property_add_defaults (mbox->property, | ||
438 | mbox->properties[i].key, | ||
439 | mbox->properties[i].value, | ||
440 | mbox->properties[i]._set_value, | ||
441 | mbox->properties[i]._get_value, | ||
442 | mbox); | ||
443 | if (status != 0) | ||
444 | { | ||
445 | property_destroy (&(mbox->property), mbox); | ||
446 | return status; | ||
447 | } | ||
448 | } | ||
449 | } | 422 | } |
450 | *pproperty = mbox->property; | 423 | *pproperty = mbox->property; |
451 | return 0; | 424 | return 0; |
... | @@ -456,14 +429,8 @@ mailbox_set_debug (mailbox_t mbox, mu_debug_t debug) | ... | @@ -456,14 +429,8 @@ mailbox_set_debug (mailbox_t mbox, mu_debug_t debug) |
456 | { | 429 | { |
457 | if (mbox == NULL) | 430 | if (mbox == NULL) |
458 | return EINVAL; | 431 | return EINVAL; |
459 | if (mbox->folder) | ||
460 | { | ||
461 | int status = folder_set_debug (mbox->folder, debug); | ||
462 | if (status) | ||
463 | return status; | ||
464 | } | ||
465 | if (mbox->debug) | 432 | if (mbox->debug) |
466 | mu_debug_destroy (&(mbox->debug), mbox); | 433 | mu_debug_destroy (&mbox->debug, mbox); |
467 | mbox->debug = debug; | 434 | mbox->debug = debug; |
468 | return 0; | 435 | return 0; |
469 | } | 436 | } |
... | @@ -473,17 +440,6 @@ mailbox_get_debug (mailbox_t mbox, mu_debug_t *pdebug) | ... | @@ -473,17 +440,6 @@ mailbox_get_debug (mailbox_t mbox, mu_debug_t *pdebug) |
473 | { | 440 | { |
474 | if (mbox == NULL || pdebug == NULL) | 441 | if (mbox == NULL || pdebug == NULL) |
475 | return EINVAL; | 442 | return EINVAL; |
476 | if (mbox->folder) | ||
477 | { | ||
478 | int status = folder_get_debug (mbox->folder, pdebug); | ||
479 | if (status == 0) | ||
480 | { | ||
481 | if (mbox->debug) | ||
482 | mu_debug_destroy (&(mbox->debug), mbox); | ||
483 | mbox->debug = *pdebug; | ||
484 | } | ||
485 | return status; | ||
486 | } | ||
487 | if (mbox->debug == NULL) | 443 | if (mbox->debug == NULL) |
488 | { | 444 | { |
489 | int status = mu_debug_create (&(mbox->debug), mbox); | 445 | int status = mu_debug_create (&(mbox->debug), mbox); | ... | ... |
... | @@ -138,19 +138,6 @@ mailer_destroy (mailer_t *pmailer) | ... | @@ -138,19 +138,6 @@ mailer_destroy (mailer_t *pmailer) |
138 | if (mailer->debug) | 138 | if (mailer->debug) |
139 | mu_debug_destroy (&(mailer->debug), mailer); | 139 | mu_debug_destroy (&(mailer->debug), mailer); |
140 | 140 | ||
141 | if (mailer->properties) | ||
142 | { | ||
143 | size_t i; | ||
144 | for (i = 0; i < mailer->properties_count; i++) | ||
145 | { | ||
146 | if (mailer->properties[i].key) | ||
147 | free (mailer->properties[i].key); | ||
148 | if (mailer->properties[i].value) | ||
149 | free (mailer->properties[i].value); | ||
150 | } | ||
151 | free (mailer->properties); | ||
152 | } | ||
153 | |||
154 | if (mailer->property) | 141 | if (mailer->property) |
155 | property_destroy (&(mailer->property), mailer); | 142 | property_destroy (&(mailer->property), mailer); |
156 | 143 | ||
... | @@ -232,25 +219,9 @@ mailer_get_property (mailer_t mailer, property_t *pproperty) | ... | @@ -232,25 +219,9 @@ mailer_get_property (mailer_t mailer, property_t *pproperty) |
232 | return EINVAL; | 219 | return EINVAL; |
233 | if (mailer->property == NULL) | 220 | if (mailer->property == NULL) |
234 | { | 221 | { |
235 | size_t i; | ||
236 | int status = property_create (&(mailer->property), mailer); | 222 | int status = property_create (&(mailer->property), mailer); |
237 | if (status != 0) | 223 | if (status != 0) |
238 | return status; | 224 | return status; |
239 | /* Add the defaults. */ | ||
240 | for (i = 0; i < mailer->properties_count; i++) | ||
241 | { | ||
242 | status = property_add_defaults (mailer->property, | ||
243 | mailer->properties[i].key, | ||
244 | mailer->properties[i].value, | ||
245 | mailer->properties[i]._set_value, | ||
246 | mailer->properties[i]._get_value, | ||
247 | mailer); | ||
248 | if (status != 0) | ||
249 | { | ||
250 | property_destroy (&(mailer->property), mailer); | ||
251 | return status; | ||
252 | } | ||
253 | } | ||
254 | } | 225 | } |
255 | *pproperty = mailer->property; | 226 | *pproperty = mailer->property; |
256 | return 0; | 227 | return 0; | ... | ... |
... | @@ -51,6 +51,7 @@ static int imap_messages_count __P ((mailbox_t, size_t *)); | ... | @@ -51,6 +51,7 @@ static int imap_messages_count __P ((mailbox_t, size_t *)); |
51 | static int imap_messages_recent __P ((mailbox_t, size_t *)); | 51 | static int imap_messages_recent __P ((mailbox_t, size_t *)); |
52 | static int imap_message_unseen __P ((mailbox_t, size_t *)); | 52 | static int imap_message_unseen __P ((mailbox_t, size_t *)); |
53 | static int imap_scan __P ((mailbox_t, size_t, size_t *)); | 53 | static int imap_scan __P ((mailbox_t, size_t, size_t *)); |
54 | static int imap_scan0 __P ((mailbox_t, size_t, size_t *, int)); | ||
54 | static int imap_is_updated __P ((mailbox_t)); | 55 | static int imap_is_updated __P ((mailbox_t)); |
55 | static int imap_append_message __P ((mailbox_t, message_t)); | 56 | static int imap_append_message __P ((mailbox_t, message_t)); |
56 | static int imap_copy_message __P ((mailbox_t, message_t)); | 57 | static int imap_copy_message __P ((mailbox_t, message_t)); |
... | @@ -148,12 +149,11 @@ _mailbox_imap_init (mailbox_t mailbox) | ... | @@ -148,12 +149,11 @@ _mailbox_imap_init (mailbox_t mailbox) |
148 | m_imap->mailbox = mailbox; | 149 | m_imap->mailbox = mailbox; |
149 | 150 | ||
150 | /* Set our properties. */ | 151 | /* Set our properties. */ |
151 | mailbox->properties = calloc (1, sizeof (*(mailbox->properties))); | 152 | { |
152 | if (mailbox->properties == NULL) | 153 | property_t property = NULL; |
153 | return ENOMEM; | 154 | mailbox_get_property (mailbox, &property); |
154 | mailbox->properties_count = 1; | 155 | property_set_value (property, "TYPE", "IMAP4", 1); |
155 | mailbox->properties[0].key = strdup ("TYPE"); | 156 | } |
156 | mailbox->properties[0].value = strdup ("IMAP"); | ||
157 | return 0; | 157 | return 0; |
158 | } | 158 | } |
159 | 159 | ||
... | @@ -218,11 +218,13 @@ mailbox_imap_destroy (mailbox_t mailbox) | ... | @@ -218,11 +218,13 @@ mailbox_imap_destroy (mailbox_t mailbox) |
218 | static int | 218 | static int |
219 | mailbox_imap_open (mailbox_t mailbox, int flags) | 219 | mailbox_imap_open (mailbox_t mailbox, int flags) |
220 | { | 220 | { |
221 | mailbox->flags = flags; | ||
221 | return folder_open (mailbox->folder, flags); | 222 | return folder_open (mailbox->folder, flags); |
222 | } | 223 | } |
223 | 224 | ||
224 | /* We can not close the folder in term of shuting down the connection but if | 225 | /* We can not close the folder in term of shuting down the connection but if |
225 | we were the selected mailbox we send the close and deselect ourself. */ | 226 | we were the selected mailbox we send the close and deselect ourself. |
227 | The CLOSE is also use to expunge instead of sending expunge. */ | ||
226 | static int | 228 | static int |
227 | mailbox_imap_close (mailbox_t mailbox) | 229 | mailbox_imap_close (mailbox_t mailbox) |
228 | { | 230 | { |
... | @@ -501,6 +503,16 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum) | ... | @@ -501,6 +503,16 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum) |
501 | f_imap_t f_imap = m_imap->f_imap; | 503 | f_imap_t f_imap = m_imap->f_imap; |
502 | int status = 0; | 504 | int status = 0; |
503 | 505 | ||
506 | /* FIXME: It is debatable if we should reconnect when the connection | ||
507 | timeout or die. For timeout client should ping i.e. send | ||
508 | a NOOP via imap_is_updated() function to keep the connection alive. */ | ||
509 | if (!f_imap->isopen) | ||
510 | { | ||
511 | status = folder_open (mailbox->folder, mailbox->flags); | ||
512 | if (status != 0) | ||
513 | return status; | ||
514 | } | ||
515 | |||
504 | /* Are we already selected ? */ | 516 | /* Are we already selected ? */ |
505 | if (m_imap == (f_imap->selected)) | 517 | if (m_imap == (f_imap->selected)) |
506 | { | 518 | { |
... | @@ -544,6 +556,12 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum) | ... | @@ -544,6 +556,12 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum) |
544 | return status; | 556 | return status; |
545 | } | 557 | } |
546 | 558 | ||
559 | static int | ||
560 | imap_scan (mailbox_t mailbox, size_t msgno, size_t *pcount) | ||
561 | { | ||
562 | return imap_scan0 (mailbox, msgno, pcount , 1); | ||
563 | } | ||
564 | |||
547 | /* Usually when this function is call it is because there is an oberver | 565 | /* Usually when this function is call it is because there is an oberver |
548 | attach an the client is try to build some sort of list/tree header | 566 | attach an the client is try to build some sort of list/tree header |
549 | as the scanning progress. But doing this for each message can be | 567 | 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) | ... | @@ -553,7 +571,7 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum) |
553 | transcation but rather a big one. The bad thing is that every thing | 571 | transcation but rather a big one. The bad thing is that every thing |
554 | will be cache in the structure using a lot of memory. */ | 572 | will be cache in the structure using a lot of memory. */ |
555 | static int | 573 | static int |
556 | imap_scan (mailbox_t mailbox, size_t msgno, size_t *pcount) | 574 | imap_scan0 (mailbox_t mailbox, size_t msgno, size_t *pcount, int notif) |
557 | { | 575 | { |
558 | int status; | 576 | int status; |
559 | size_t i; | 577 | size_t i; |
... | @@ -596,11 +614,15 @@ imap_scan (mailbox_t mailbox, size_t msgno, size_t *pcount) | ... | @@ -596,11 +614,15 @@ imap_scan (mailbox_t mailbox, size_t msgno, size_t *pcount) |
596 | 614 | ||
597 | f_imap->state = IMAP_NO_STATE; | 615 | f_imap->state = IMAP_NO_STATE; |
598 | 616 | ||
617 | /* Do not send notifications. */ | ||
618 | if (!notif) | ||
619 | return 0; | ||
620 | |||
599 | /* If no callbacks bail out early. */ | 621 | /* If no callbacks bail out early. */ |
600 | if (mailbox->observable == NULL) | 622 | if (mailbox->observable == NULL) |
601 | return 0; | 623 | return 0; |
602 | 624 | ||
603 | for (i = msgno; i <= *pcount; i++) | 625 | for (i = msgno; i <= count; i++) |
604 | { | 626 | { |
605 | if (observable_notify (mailbox->observable, MU_EVT_MESSAGE_ADD) != 0) | 627 | if (observable_notify (mailbox->observable, MU_EVT_MESSAGE_ADD) != 0) |
606 | break; | 628 | break; |
... | @@ -704,14 +726,24 @@ imap_expunge (mailbox_t mailbox) | ... | @@ -704,14 +726,24 @@ imap_expunge (mailbox_t mailbox) |
704 | MAILBOX_DEBUG0 (m_imap->mailbox, MU_DEBUG_PROT, f_imap->buffer); | 726 | MAILBOX_DEBUG0 (m_imap->mailbox, MU_DEBUG_PROT, f_imap->buffer); |
705 | f_imap->state = IMAP_NO_STATE; | 727 | f_imap->state = IMAP_NO_STATE; |
706 | 728 | ||
729 | /* We are not sending EXPUNGE, rather we close the mailbox | ||
730 | which will purge. */ | ||
731 | case IMAP_CLOSE: | ||
732 | case IMAP_CLOSE_ACK: | ||
733 | status = mailbox_imap_close (mailbox); | ||
734 | CHECK_EAGAIN (f_imap, status); | ||
735 | |||
736 | /* Rescan after expunging but do not trigger the observers. */ | ||
737 | case IMAP_SCAN: | ||
738 | case IMAP_SCAN_ACK: | ||
739 | status = imap_scan0 (mailbox, 1, NULL, 0); | ||
740 | CHECK_EAGAIN (f_imap, status); | ||
741 | |||
707 | default: | 742 | default: |
708 | /* mu_error ("imap_expunge: unknow state\n"); */ | 743 | /* mu_error ("imap_expunge: unknow state\n"); */ |
709 | break; | 744 | break; |
710 | } | 745 | } |
711 | 746 | ||
712 | /* Tell the server to delete the messages but without sending the | ||
713 | EXPUNGE response. We can do the calculations. */ | ||
714 | status = mailbox_imap_close (mailbox); | ||
715 | return status; | 747 | return status; |
716 | } | 748 | } |
717 | 749 | ... | ... |
... | @@ -278,12 +278,11 @@ _mailbox_mbox_init (mailbox_t mailbox) | ... | @@ -278,12 +278,11 @@ _mailbox_mbox_init (mailbox_t mailbox) |
278 | mailbox->_get_size = mbox_get_size; | 278 | mailbox->_get_size = mbox_get_size; |
279 | 279 | ||
280 | /* Set our properties. */ | 280 | /* Set our properties. */ |
281 | mailbox->properties = calloc (1, sizeof (*(mailbox->properties))); | 281 | { |
282 | if (mailbox->properties == NULL) | 282 | property_t property = NULL; |
283 | return ENOMEM; | 283 | mailbox_get_property (mailbox, &property); |
284 | mailbox->properties_count = 1; | 284 | property_set_value (property, "TYPE", "MBOX", 1); |
285 | mailbox->properties[0].key = strdup ("TYPE"); | 285 | } |
286 | mailbox->properties[0].value = strdup ("MBOX"); | ||
287 | 286 | ||
288 | MAILBOX_DEBUG1 (mailbox, MU_DEBUG_TRACE, "mbox_init(%s)\n", mud->name); | 287 | MAILBOX_DEBUG1 (mailbox, MU_DEBUG_TRACE, "mbox_init(%s)\n", mud->name); |
289 | return 0; /* okdoke */ | 288 | return 0; /* okdoke */ | ... | ... |
... | @@ -217,12 +217,11 @@ _mailbox_mh_init (mailbox_t mailbox) | ... | @@ -217,12 +217,11 @@ _mailbox_mh_init (mailbox_t mailbox) |
217 | mailbox->_get_size = mh_get_size; | 217 | mailbox->_get_size = mh_get_size; |
218 | 218 | ||
219 | /* Set our properties. */ | 219 | /* Set our properties. */ |
220 | mailbox->properties = calloc (1, sizeof (*mailbox->properties)); | 220 | { |
221 | if (mailbox->properties == NULL) | 221 | property_t property = NULL; |
222 | return ENOMEM; | 222 | mailbox_get_property (mailbox, &property); |
223 | mailbox->properties_count = 1; | 223 | property_set_value (property, "TYPE", "MH", 1); |
224 | mailbox->properties[0].key = strdup ("TYPE"); | 224 | } |
225 | mailbox->properties[0].value = strdup ("MH"); | ||
226 | 225 | ||
227 | MAILBOX_DEBUG1 (mailbox, MU_DEBUG_TRACE, "mh_init(%s)\n", mhd->name); | 226 | MAILBOX_DEBUG1 (mailbox, MU_DEBUG_TRACE, "mh_init(%s)\n", mhd->name); |
228 | return 0; | 227 | return 0; | ... | ... |
... | @@ -353,38 +353,16 @@ _mailbox_pop_init (mailbox_t mbox) | ... | @@ -353,38 +353,16 @@ _mailbox_pop_init (mailbox_t mbox) |
353 | 353 | ||
354 | mbox->_get_size = pop_get_size; | 354 | mbox->_get_size = pop_get_size; |
355 | 355 | ||
356 | /* Properties. */ | 356 | /* Set our properties. */ |
357 | mbox->properties = calloc (1, sizeof (*(mbox->properties))); | 357 | { |
358 | if (mbox->properties == NULL) | 358 | property_t property = NULL; |
359 | { | 359 | mailbox_get_property (mbox, &property); |
360 | status = ENOMEM; | 360 | property_set_value (property, "TYPE", "POP3", 1); |
361 | goto END; | 361 | } |
362 | } | ||
363 | mbox->properties_count = 1; | ||
364 | mbox->properties[0].key = strdup ("TYPE"); | ||
365 | mbox->properties[0].value = strdup ("POP3"); | ||
366 | if (mbox->properties[0].key == NULL || mbox->properties[0].value == NULL) | ||
367 | { | ||
368 | status = ENOMEM; | ||
369 | goto END; | ||
370 | } | ||
371 | 362 | ||
372 | /* Hack! */ | 363 | /* Hack! POP does not really have a folder. */ |
373 | mbox->folder->data = mbox; | 364 | mbox->folder->data = mbox; |
374 | 365 | ||
375 | END: | ||
376 | if (status != 0) | ||
377 | { | ||
378 | if (mbox->properties[0].key) | ||
379 | free (mbox->properties[0].key); | ||
380 | if (mbox->properties[0].value) | ||
381 | free (mbox->properties[0].value); | ||
382 | if (mbox->properties) | ||
383 | free (mbox->properties); | ||
384 | if (mbox->data) | ||
385 | free (mbox->data); | ||
386 | } | ||
387 | |||
388 | return status; | 366 | return status; |
389 | } | 367 | } |
390 | 368 | ... | ... |
... | @@ -117,10 +117,10 @@ MD5_CTX *context; /* context */ | ... | @@ -117,10 +117,10 @@ MD5_CTX *context; /* context */ |
117 | unsigned char *input; /* input block */ | 117 | unsigned char *input; /* input block */ |
118 | unsigned int inputLen; /* length of input block */ | 118 | unsigned int inputLen; /* length of input block */ |
119 | { | 119 | { |
120 | unsigned int i, index, partLen; | 120 | unsigned int i, indx, partLen; |
121 | 121 | ||
122 | /* Compute number of bytes mod 64 */ | 122 | /* Compute number of bytes mod 64 */ |
123 | index = (unsigned int)((context->count[0] >> 3) & 0x3F); | 123 | indx = (unsigned int)((context->count[0] >> 3) & 0x3F); |
124 | 124 | ||
125 | /* Update number of bits */ | 125 | /* Update number of bits */ |
126 | if ((context->count[0] += ((UINT4)inputLen << 3)) | 126 | if ((context->count[0] += ((UINT4)inputLen << 3)) |
... | @@ -128,26 +128,26 @@ unsigned int inputLen; /* length of input block */ | ... | @@ -128,26 +128,26 @@ unsigned int inputLen; /* length of input block */ |
128 | context->count[1]++; | 128 | context->count[1]++; |
129 | context->count[1] += ((UINT4)inputLen >> 29); | 129 | context->count[1] += ((UINT4)inputLen >> 29); |
130 | 130 | ||
131 | partLen = 64 - index; | 131 | partLen = 64 - indx; |
132 | 132 | ||
133 | /* Transform as many times as possible. | 133 | /* Transform as many times as possible. |
134 | */ | 134 | */ |
135 | if (inputLen >= partLen) { | 135 | if (inputLen >= partLen) { |
136 | MD5_memcpy | 136 | MD5_memcpy |
137 | ((POINTER)&context->buffer[index], (POINTER)input, partLen); | 137 | ((POINTER)&context->buffer[indx], (POINTER)input, partLen); |
138 | MD5Transform (context->state, context->buffer); | 138 | MD5Transform (context->state, context->buffer); |
139 | 139 | ||
140 | for (i = partLen; i + 63 < inputLen; i += 64) | 140 | for (i = partLen; i + 63 < inputLen; i += 64) |
141 | MD5Transform (context->state, &input[i]); | 141 | MD5Transform (context->state, &input[i]); |
142 | 142 | ||
143 | index = 0; | 143 | indx = 0; |
144 | } | 144 | } |
145 | else | 145 | else |
146 | i = 0; | 146 | i = 0; |
147 | 147 | ||
148 | /* Buffer remaining input */ | 148 | /* Buffer remaining input */ |
149 | MD5_memcpy | 149 | MD5_memcpy |
150 | ((POINTER)&context->buffer[index], (POINTER)&input[i], | 150 | ((POINTER)&context->buffer[indx], (POINTER)&input[i], |
151 | inputLen-i); | 151 | inputLen-i); |
152 | } | 152 | } |
153 | 153 | ||
... | @@ -159,15 +159,15 @@ unsigned char digest[16]; /* message digest */ | ... | @@ -159,15 +159,15 @@ unsigned char digest[16]; /* message digest */ |
159 | MD5_CTX *context; /* context */ | 159 | MD5_CTX *context; /* context */ |
160 | { | 160 | { |
161 | unsigned char bits[8]; | 161 | unsigned char bits[8]; |
162 | unsigned int index, padLen; | 162 | unsigned int indx, padLen; |
163 | 163 | ||
164 | /* Save number of bits */ | 164 | /* Save number of bits */ |
165 | Encode (bits, context->count, 8); | 165 | Encode (bits, context->count, 8); |
166 | 166 | ||
167 | /* Pad out to 56 mod 64. | 167 | /* Pad out to 56 mod 64. |
168 | */ | 168 | */ |
169 | index = (unsigned int)((context->count[0] >> 3) & 0x3f); | 169 | indx = (unsigned int)((context->count[0] >> 3) & 0x3f); |
170 | padLen = (index < 56) ? (56 - index) : (120 - index); | 170 | padLen = (indx < 56) ? (56 - indx) : (120 - indx); |
171 | MD5Update (context, PADDING, padLen); | 171 | MD5Update (context, PADDING, padLen); |
172 | 172 | ||
173 | /* Append length (before padding) */ | 173 | /* Append length (before padding) */ | ... | ... |
... | @@ -185,37 +185,6 @@ message_clear_modified (message_t msg) | ... | @@ -185,37 +185,6 @@ message_clear_modified (message_t msg) |
185 | } | 185 | } |
186 | 186 | ||
187 | int | 187 | int |
188 | message_set_property (message_t msg, property_t property, void *owner) | ||
189 | { | ||
190 | if (msg == NULL) | ||
191 | return EINVAL; | ||
192 | if (msg->owner != owner) | ||
193 | return EACCES; | ||
194 | header_set_property (msg->header, property, msg); | ||
195 | body_set_property (msg->body, property, msg); | ||
196 | property_destroy (&(msg->property), msg); | ||
197 | msg->property = property; | ||
198 | return 0; | ||
199 | } | ||
200 | |||
201 | int | ||
202 | message_get_property (message_t msg, property_t *pproperty) | ||
203 | { | ||
204 | if (msg == NULL || pproperty == NULL) | ||
205 | return EINVAL; | ||
206 | if (msg->property == NULL) | ||
207 | { | ||
208 | int status = property_create (&(msg->property), msg); | ||
209 | if (status != 0) | ||
210 | return status; | ||
211 | header_set_property (msg->header, msg->property, msg); | ||
212 | body_set_property (msg->body, msg->property, msg); | ||
213 | } | ||
214 | *pproperty = msg->property; | ||
215 | return 0; | ||
216 | } | ||
217 | |||
218 | int | ||
219 | message_get_mailbox (message_t msg, mailbox_t *pmailbox) | 188 | message_get_mailbox (message_t msg, mailbox_t *pmailbox) |
220 | { | 189 | { |
221 | if (msg == NULL || pmailbox == NULL) | 190 | if (msg == NULL || pmailbox == NULL) | ... | ... |
... | @@ -508,6 +508,7 @@ int parse822_word(const char** p, const char* e, char** word) | ... | @@ -508,6 +508,7 @@ int parse822_word(const char** p, const char* e, char** word) |
508 | 508 | ||
509 | return rc; | 509 | return rc; |
510 | } | 510 | } |
511 | assert(qstr == NULL); | ||
511 | } | 512 | } |
512 | 513 | ||
513 | if(rc != EPARSE) { | 514 | if(rc != EPARSE) { |
... | @@ -532,6 +533,7 @@ int parse822_word(const char** p, const char* e, char** word) | ... | @@ -532,6 +533,7 @@ int parse822_word(const char** p, const char* e, char** word) |
532 | 533 | ||
533 | return rc; | 534 | return rc; |
534 | } | 535 | } |
536 | assert (atom == NULL); | ||
535 | } | 537 | } |
536 | 538 | ||
537 | return EPARSE; | 539 | return EPARSE; |
... | @@ -562,6 +564,7 @@ int parse822_phrase(const char** p, const char* e, char** phrase) | ... | @@ -562,6 +564,7 @@ int parse822_phrase(const char** p, const char* e, char** phrase) |
562 | if(rc != EOK) | 564 | if(rc != EOK) |
563 | break; | 565 | break; |
564 | } | 566 | } |
567 | assert(word == NULL); | ||
565 | if(rc == EPARSE) | 568 | if(rc == EPARSE) |
566 | rc = EOK; /* its not an error to find no more words */ | 569 | rc = EOK; /* its not an error to find no more words */ |
567 | } | 570 | } |
... | @@ -713,6 +716,7 @@ int parse822_group(const char** p, const char* e, address_t* a) | ... | @@ -713,6 +716,7 @@ int parse822_group(const char** p, const char* e, address_t* a) |
713 | 716 | ||
714 | if((rc = parse822_special(p, e, ':'))) { | 717 | if((rc = parse822_special(p, e, ':'))) { |
715 | *p = save; | 718 | *p = save; |
719 | str_free(&phrase); | ||
716 | return rc; | 720 | return rc; |
717 | } | 721 | } |
718 | 722 | ||
... | @@ -807,12 +811,9 @@ int parse822_mail_box(const char** p, const char* e, address_t* a) | ... | @@ -807,12 +811,9 @@ int parse822_mail_box(const char** p, const char* e, address_t* a) |
807 | (*a)->personal = phrase; | 811 | (*a)->personal = phrase; |
808 | 812 | ||
809 | return EOK; | 813 | return EOK; |
810 | } else if(rc != EPARSE) { | ||
811 | /* some internal error, fail out */ | ||
812 | *p = save; | ||
813 | str_free(&phrase); | ||
814 | return rc; | ||
815 | } | 814 | } |
815 | /* some internal error, fail out */ | ||
816 | str_free(&phrase); | ||
816 | *p = save; | 817 | *p = save; |
817 | 818 | ||
818 | return rc; | 819 | return rc; |
... | @@ -910,10 +911,9 @@ int parse822_route(const char** p, const char* e, char** route) | ... | @@ -910,10 +911,9 @@ int parse822_route(const char** p, const char* e, char** route) |
910 | rc = str_append(route, accumulator); | 911 | rc = str_append(route, accumulator); |
911 | } | 912 | } |
912 | if(rc) { | 913 | if(rc) { |
913 | str_free(&accumulator); | ||
914 | *p = save; | 914 | *p = save; |
915 | } | 915 | } |
916 | 916 | str_free(&accumulator); | |
917 | return rc; | 917 | return rc; |
918 | } | 918 | } |
919 | 919 | ||
... | @@ -1008,8 +1008,8 @@ int parse822_local_part(const char** p, const char* e, char** local_part) | ... | @@ -1008,8 +1008,8 @@ int parse822_local_part(const char** p, const char* e, char** local_part) |
1008 | if((rc = str_append(local_part, ".")) == EOK) { | 1008 | if((rc = str_append(local_part, ".")) == EOK) { |
1009 | rc = str_append(local_part, more); | 1009 | rc = str_append(local_part, more); |
1010 | } | 1010 | } |
1011 | str_free(&more); | ||
1012 | } | 1011 | } |
1012 | str_free(&more); | ||
1013 | } | 1013 | } |
1014 | 1014 | ||
1015 | if(rc == EPARSE) { | 1015 | if(rc == EPARSE) { |
... | @@ -1062,8 +1062,8 @@ int parse822_domain(const char** p, const char* e, char** domain) | ... | @@ -1062,8 +1062,8 @@ int parse822_domain(const char** p, const char* e, char** domain) |
1062 | if((rc = str_append(domain, ".")) == EOK) { | 1062 | if((rc = str_append(domain, ".")) == EOK) { |
1063 | rc = str_append(domain, more); | 1063 | rc = str_append(domain, more); |
1064 | } | 1064 | } |
1065 | str_free(&more); | ||
1066 | } | 1065 | } |
1066 | str_free(&more); | ||
1067 | } | 1067 | } |
1068 | if(rc == EPARSE) { | 1068 | if(rc == EPARSE) { |
1069 | /* we didn't parse more ("." sub-domain) pairs, that's ok */ | 1069 | /* we didn't parse more ("." sub-domain) pairs, that's ok */ | ... | ... |
... | @@ -24,14 +24,11 @@ | ... | @@ -24,14 +24,11 @@ |
24 | 24 | ||
25 | #include <property0.h> | 25 | #include <property0.h> |
26 | 26 | ||
27 | static int property_find __P ((list_t, const char *, struct property_data **)); | 27 | #undef min |
28 | static int property_add __P ((property_t, const char *, const char *, | 28 | #define min(a,b) ((a) < (b) ? (a) : (b)) |
29 | int (*_set_value) | 29 | |
30 | __P ((property_t, const char *, const char *)), | 30 | static int property_find __P ((property_t, const char *, |
31 | int (*_get_value) | 31 | struct property_item **)); |
32 | __P ((property_t, const char *, char *, | ||
33 | size_t, size_t *)))); | ||
34 | static size_t property_hash __P ((const char *)); | ||
35 | 32 | ||
36 | int | 33 | int |
37 | property_create (property_t *pp, void *owner) | 34 | property_create (property_t *pp, void *owner) |
... | @@ -39,9 +36,10 @@ property_create (property_t *pp, void *owner) | ... | @@ -39,9 +36,10 @@ property_create (property_t *pp, void *owner) |
39 | property_t prop; | 36 | property_t prop; |
40 | if (pp == NULL) | 37 | if (pp == NULL) |
41 | return EINVAL; | 38 | return EINVAL; |
42 | prop = calloc (1, sizeof (*prop)); | 39 | prop = calloc (1, sizeof *prop); |
43 | if (prop == NULL) | 40 | if (prop == NULL) |
44 | return ENOMEM; | 41 | return ENOMEM; |
42 | monitor_create (&prop->lock, 0, prop); | ||
45 | prop->owner = owner; | 43 | prop->owner = owner; |
46 | *pp = prop; | 44 | *pp = prop; |
47 | return 0; | 45 | return 0; |
... | @@ -55,29 +53,20 @@ property_destroy (property_t *pp, void *owner) | ... | @@ -55,29 +53,20 @@ property_destroy (property_t *pp, void *owner) |
55 | property_t prop = *pp; | 53 | property_t prop = *pp; |
56 | if (prop->owner == owner) | 54 | if (prop->owner == owner) |
57 | { | 55 | { |
56 | struct property_item *item, *cur; | ||
58 | /* Destroy the list and is properties. */ | 57 | /* Destroy the list and is properties. */ |
59 | if (prop->list) | 58 | monitor_wrlock (prop->lock); |
59 | for (item = prop->items; item; item = cur) | ||
60 | { | 60 | { |
61 | struct property_data *pd = NULL; | 61 | if (item->key) |
62 | iterator_t iterator = NULL; | 62 | free (item->key); |
63 | 63 | if (item->value) | |
64 | iterator_create (&iterator, prop->list); | 64 | free (item->value); |
65 | for (iterator_first (iterator); !iterator_is_done (iterator); | 65 | cur = item->next; |
66 | iterator_next (iterator)) | 66 | free (item); |
67 | { | ||
68 | iterator_current (iterator, (void **)&pd); | ||
69 | if (pd) | ||
70 | { | ||
71 | if (pd->key) | ||
72 | free (pd->key); | ||
73 | if (pd->value) | ||
74 | free (pd->value); | ||
75 | free (pd); | ||
76 | } | ||
77 | } | ||
78 | iterator_destroy (&iterator); | ||
79 | list_destroy (&(prop->list)); | ||
80 | } | 67 | } |
68 | monitor_unlock (prop->lock); | ||
69 | monitor_destroy (&prop->lock, prop); | ||
81 | free (prop); | 70 | free (prop); |
82 | } | 71 | } |
83 | *pp = NULL; | 72 | *pp = NULL; |
... | @@ -91,214 +80,137 @@ property_get_owner (property_t prop) | ... | @@ -91,214 +80,137 @@ property_get_owner (property_t prop) |
91 | } | 80 | } |
92 | 81 | ||
93 | int | 82 | int |
94 | property_add_defaults (property_t prop, const char *key, const char *value, | 83 | property_set_value (property_t prop, const char *key, const char *value, |
95 | int (*_set_value) __P ((property_t, const char *, | 84 | int overwrite) |
96 | const char *)), | ||
97 | int (*_get_value) __P ((property_t, const char *, | ||
98 | char *, size_t, size_t *)), | ||
99 | void *owner) | ||
100 | { | ||
101 | if (prop == NULL) | ||
102 | return EINVAL; | ||
103 | if (prop->owner != owner) | ||
104 | return EACCES; | ||
105 | return property_add (prop, key, value, _set_value, _get_value); | ||
106 | } | ||
107 | |||
108 | int | ||
109 | property_set_value (property_t prop, const char *key, const char *value) | ||
110 | { | 85 | { |
86 | struct property_item *item; | ||
87 | int status = property_find (prop, key, &item); | ||
88 | if (status != 0) | ||
89 | return status; | ||
111 | 90 | ||
112 | if (prop == NULL) | 91 | if (item->set) |
113 | return EINVAL; | 92 | { |
114 | return property_add (prop, key, value, NULL, NULL); | 93 | if (overwrite) |
94 | { | ||
95 | item->set = 0; | ||
96 | if (item->value) | ||
97 | free (item->value); | ||
98 | item->value = NULL; | ||
99 | if (value) | ||
100 | { | ||
101 | item->set = 1; | ||
102 | item->value = strdup (value); | ||
103 | if (item->value == NULL) | ||
104 | status = ENOMEM; | ||
105 | } | ||
106 | } | ||
107 | } | ||
108 | else | ||
109 | { | ||
110 | item->set = 1; | ||
111 | if (item->value) | ||
112 | free (item->value); | ||
113 | if (value) | ||
114 | { | ||
115 | item->value = strdup (value); | ||
116 | if (item->value == NULL) | ||
117 | status = ENOMEM; | ||
118 | } | ||
119 | } | ||
120 | return status; | ||
115 | } | 121 | } |
116 | 122 | ||
117 | int | 123 | int |
118 | property_get_value (property_t prop, const char *key, char *buffer, | 124 | property_get_value (property_t prop, const char *key, char *buffer, |
119 | size_t buflen, size_t *n) | 125 | size_t buflen, size_t *n) |
120 | { | 126 | { |
121 | struct property_data *pd = NULL; | 127 | struct property_item *item = NULL; |
122 | int status; | 128 | int status; |
123 | size_t len; | 129 | size_t len; |
124 | 130 | ||
125 | if (prop == NULL) | 131 | status = property_find (prop, key, &item); |
126 | return EINVAL; | ||
127 | |||
128 | status = property_find (prop->list, key, &pd); | ||
129 | if (status != 0) | 132 | if (status != 0) |
130 | return status; | 133 | return status; |
131 | 134 | ||
132 | if (pd == NULL) | 135 | len = (item->value) ? strlen (item->value) : 0; |
133 | return ENOENT; | ||
134 | |||
135 | if (pd->_get_value) | ||
136 | return pd->_get_value (prop, key, buffer, buflen, n); | ||
137 | |||
138 | len = (pd->value) ? strlen (pd->value) : 0; | ||
139 | if (buffer && buflen != 0) | 136 | if (buffer && buflen != 0) |
140 | { | 137 | { |
141 | buflen--; | 138 | buflen--; |
142 | len = (buflen < len) ? buflen : len; | 139 | len = min (buflen, len); |
143 | strncpy (buffer, pd->value, len)[len] = '\0'; | 140 | strncpy (buffer, item->value, len)[len] = '\0'; |
144 | } | 141 | } |
145 | if (n) | 142 | if (n) |
146 | *n = len; | 143 | *n = len; |
147 | return 0; | 144 | return 0; |
148 | } | 145 | } |
149 | 146 | ||
150 | #if 0 | ||
151 | int | ||
152 | property_load (property_t prop, stream_t stream) | ||
153 | { | ||
154 | size_t n = 0; | ||
155 | off_t off = 0; | ||
156 | int status; | ||
157 | int buflen = 512; | ||
158 | char *buf = calloc (buflen, sizeof (*buf)); | ||
159 | if (buf == NULL) | ||
160 | return ENOMEM; | ||
161 | |||
162 | while ((status = stream_readline (stream, buf, buflen, off, &n)) == 0 | ||
163 | && n > 0) | ||
164 | { | ||
165 | char *sep; | ||
166 | if (buf[n] != '\n') | ||
167 | { | ||
168 | char *tmp; | ||
169 | buflen *= 2; | ||
170 | tmp = realloc (buf, buflen); | ||
171 | if (tmp == NULL) | ||
172 | { | ||
173 | free (buf); | ||
174 | return ENOMEM; | ||
175 | } | ||
176 | buf = tmp; | ||
177 | continue; | ||
178 | } | ||
179 | sep = strchr (buf, '='); | ||
180 | if (sep) | ||
181 | { | ||
182 | *sep++ = '\0'; | ||
183 | property_set_value (prop, buf, sep); | ||
184 | } | ||
185 | else | ||
186 | property_set (prop, buf); | ||
187 | } | ||
188 | return 0; | ||
189 | } | ||
190 | #endif | ||
191 | |||
192 | int | 147 | int |
193 | property_set (property_t prop, const char *k) | 148 | property_set (property_t prop, const char *k) |
194 | { | 149 | { |
195 | if (!property_is_set (prop, k)) | 150 | struct property_item *item = NULL; |
196 | return property_set_value (prop, k, "1"); | 151 | int status = property_find (prop, k, &item); |
152 | if (status != 0) | ||
153 | return status; | ||
154 | item->set = 1; | ||
197 | return 0; | 155 | return 0; |
198 | } | 156 | } |
199 | 157 | ||
200 | int | 158 | int |
201 | property_unset (property_t prop, const char *k) | 159 | property_unset (property_t prop, const char *k) |
202 | { | 160 | { |
203 | if (property_is_set (prop, k)) | 161 | struct property_item *item = NULL; |
204 | return property_set_value (prop, k, NULL); | 162 | int status = property_find (prop, k, &item); |
163 | if (status != 0) | ||
164 | return status; | ||
165 | item->set = 0; | ||
205 | return 0; | 166 | return 0; |
206 | } | 167 | } |
207 | 168 | ||
208 | int | 169 | int |
209 | property_is_set (property_t prop, const char *k) | 170 | property_is_set (property_t prop, const char *k) |
210 | { | 171 | { |
211 | size_t n = 0; | 172 | struct property_item *item = NULL; |
212 | property_get_value (prop, k, NULL, 0, &n); | 173 | int status = property_find (prop, k, &item); |
213 | return (n != 0); | ||
214 | } | ||
215 | |||
216 | /* Taking from an article in Dr Dobbs. */ | ||
217 | static size_t | ||
218 | property_hash (const char *s) | ||
219 | { | ||
220 | size_t hashval; | ||
221 | for (hashval = 0; *s != '\0' ; s++) | ||
222 | { | ||
223 | hashval += (unsigned)*s ; | ||
224 | hashval += (hashval << 10); | ||
225 | hashval ^= (hashval >> 6) ; | ||
226 | } | ||
227 | hashval += (hashval << 3); | ||
228 | hashval ^= (hashval >> 11); | ||
229 | hashval += (hashval << 15); | ||
230 | return hashval; | ||
231 | } | ||
232 | |||
233 | static int | ||
234 | property_find (list_t list, const char *key, struct property_data **p) | ||
235 | { | ||
236 | int status; | ||
237 | size_t h; | ||
238 | struct property_data *pd = NULL; | ||
239 | iterator_t iterator; | ||
240 | |||
241 | status = iterator_create (&iterator, list); | ||
242 | if (status != 0) | 174 | if (status != 0) |
243 | return status; | 175 | return 0; |
244 | 176 | return item->set; | |
245 | h = property_hash (key); | ||
246 | for (iterator_first (iterator); !iterator_is_done (iterator); | ||
247 | iterator_next (iterator)) | ||
248 | { | ||
249 | iterator_current (iterator, (void **)&pd); | ||
250 | if (pd) | ||
251 | { | ||
252 | if (pd->hash == h) | ||
253 | if (pd->key && strcasecmp (pd->key, key) == 0) | ||
254 | break; | ||
255 | } | ||
256 | pd = NULL; | ||
257 | } | ||
258 | iterator_destroy (&iterator); | ||
259 | *p = pd; | ||
260 | return 0; | ||
261 | } | 177 | } |
262 | 178 | ||
263 | static int | 179 | static int |
264 | property_add (property_t prop, const char *key, const char *value, | 180 | property_find (property_t prop, const char *key, struct property_item **item) |
265 | int (*_set_value) __P ((property_t, const char *, const char *)), | ||
266 | int (*_get_value) __P ((property_t, const char *, char *, | ||
267 | size_t, size_t *))) | ||
268 | { | 181 | { |
269 | struct property_data *pd = NULL; | 182 | size_t len = 0; |
270 | int status; | 183 | struct property_item *cur = NULL; |
271 | 184 | ||
272 | if (key == NULL || *key == '\0') | 185 | if (prop == NULL || key == NULL) |
273 | return EINVAL; | 186 | return EINVAL; |
274 | 187 | ||
275 | if (prop->list == NULL) | 188 | monitor_wrlock (prop->lock); |
189 | for (len = strlen (key), cur = prop->items; cur; cur = cur->next) | ||
276 | { | 190 | { |
277 | status = list_create (&(prop->list)); | 191 | if (strlen (cur->key) == len && !strcmp (key, cur->key)) |
278 | if (status != 0) | 192 | break; |
279 | return status; | ||
280 | } | 193 | } |
281 | 194 | ||
282 | status = property_find (prop->list, key, &pd); | 195 | if (cur == NULL) |
283 | if (status != 0) | ||
284 | return status; | ||
285 | |||
286 | /* None find create a new one. */ | ||
287 | if (pd == NULL) | ||
288 | { | 196 | { |
289 | pd = calloc (1, sizeof (*pd)); | 197 | cur = calloc (1, sizeof *cur); |
290 | if (pd == NULL) | 198 | if (cur == NULL) |
291 | return ENOMEM; | 199 | { |
292 | pd->hash = property_hash (key); | 200 | monitor_unlock (prop->lock); |
293 | list_append (prop->list, (void *)pd); | 201 | return ENOMEM; |
202 | } | ||
203 | cur->key = strdup (key); | ||
204 | if (cur->key == NULL) | ||
205 | { | ||
206 | monitor_unlock (prop->lock); | ||
207 | free (cur); | ||
208 | return ENOMEM; | ||
209 | } | ||
210 | cur->next = prop->items; | ||
211 | prop->items = cur; | ||
294 | } | 212 | } |
295 | 213 | *item = cur; | |
296 | if (pd->key == NULL) | 214 | monitor_unlock (prop->lock); |
297 | pd->key = strdup (key); | ||
298 | if (pd->value) | ||
299 | free (pd->value); | ||
300 | pd->value = (value) ? strdup (value) : NULL; | ||
301 | pd->_set_value = _set_value; | ||
302 | pd->_get_value = _get_value; | ||
303 | return 0; | 215 | return 0; |
304 | } | 216 | } | ... | ... |
... | @@ -82,12 +82,11 @@ _mailer_sendmail_init (mailer_t mailer) | ... | @@ -82,12 +82,11 @@ _mailer_sendmail_init (mailer_t mailer) |
82 | mailer->_send_message = sendmail_send_message; | 82 | mailer->_send_message = sendmail_send_message; |
83 | 83 | ||
84 | /* Set our properties. */ | 84 | /* Set our properties. */ |
85 | mailer->properties = calloc (1, sizeof (*(mailer->properties))); | 85 | { |
86 | if (mailer->properties == NULL) | 86 | property_t property = NULL; |
87 | return ENOMEM; | 87 | mailer_get_property (mailer, &property); |
88 | mailer->properties_count = 1; | 88 | property_set_value (property, "TYPE", "SENDMAIL", 1); |
89 | mailer->properties[0].key = strdup ("TYPE"); | 89 | } |
90 | mailer->properties[0].value = strdup ("SENDMAIL"); | ||
91 | return 0; | 90 | return 0; |
92 | } | 91 | } |
93 | 92 | ... | ... |
... | @@ -161,12 +161,11 @@ _mailer_smtp_init (mailer_t mailer) | ... | @@ -161,12 +161,11 @@ _mailer_smtp_init (mailer_t mailer) |
161 | mailer->_send_message = smtp_send_message; | 161 | mailer->_send_message = smtp_send_message; |
162 | 162 | ||
163 | /* Set our properties. */ | 163 | /* Set our properties. */ |
164 | mailer->properties = calloc (1, sizeof (*(mailer->properties))); | 164 | { |
165 | if (mailer->properties == NULL) | 165 | property_t property = NULL; |
166 | return ENOMEM; | 166 | mailer_get_property (mailer, &property); |
167 | mailer->properties_count = 1; | 167 | property_set_value (property, "TYPE", "SMTP", 1); |
168 | mailer->properties[0].key = strdup ("TYPE"); | 168 | } |
169 | mailer->properties[0].value = strdup ("SMTP"); | ||
170 | 169 | ||
171 | return 0; | 170 | return 0; |
172 | } | 171 | } | ... | ... |
-
Please register or sign in to post a comment