(registrar_get_list): Split into two
calls. The registrar_get_list proper is deprecated. (registrar_get_iterator,registrar_lookup): New functions (registrar_record,unregistrar_record): Use _registrar_get_list
Showing
1 changed file
with
84 additions
and
7 deletions
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2000, 2001, 2004 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc. |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Lesser General Public | 5 | modify it under the terms of the GNU Lesser General Public |
... | @@ -31,18 +31,21 @@ | ... | @@ -31,18 +31,21 @@ |
31 | #include <mailutils/list.h> | 31 | #include <mailutils/list.h> |
32 | #include <mailutils/monitor.h> | 32 | #include <mailutils/monitor.h> |
33 | #include <mailutils/errno.h> | 33 | #include <mailutils/errno.h> |
34 | #include <mailutils/nls.h> | ||
35 | #include <mailutils/error.h> | ||
34 | 36 | ||
35 | #include <registrar0.h> | 37 | #include <registrar0.h> |
36 | 38 | ||
37 | /* NOTE: We will leak here since the monitor and the registrar will never | 39 | /* NOTE: We will leak here since the monitor and the registrar will never |
38 | be release. That's ok we can leave with this, it's only done once. */ | 40 | be released. That's ok we can live with this, it's only done once. */ |
39 | static list_t registrar_list; | 41 | static list_t registrar_list; |
40 | struct _monitor registrar_monitor = MU_MONITOR_INITIALIZER; | 42 | struct _monitor registrar_monitor = MU_MONITOR_INITIALIZER; |
41 | 43 | ||
42 | int | 44 | static int |
43 | registrar_get_list (list_t *plist) | 45 | _registrar_get_list (list_t *plist) |
44 | { | 46 | { |
45 | int status = 0; | 47 | int status = 0; |
48 | |||
46 | if (plist == NULL) | 49 | if (plist == NULL) |
47 | return MU_ERR_OUT_PTR_NULL; | 50 | return MU_ERR_OUT_PTR_NULL; |
48 | monitor_wrlock (®istrar_monitor); | 51 | monitor_wrlock (®istrar_monitor); |
... | @@ -53,19 +56,93 @@ registrar_get_list (list_t *plist) | ... | @@ -53,19 +56,93 @@ registrar_get_list (list_t *plist) |
53 | return status; | 56 | return status; |
54 | } | 57 | } |
55 | 58 | ||
59 | /* Provided for backward compatibility */ | ||
60 | int | ||
61 | registrar_get_list (list_t *plist) | ||
62 | { | ||
63 | static int warned; | ||
64 | |||
65 | if (!warned) | ||
66 | { | ||
67 | mu_error (_("Program uses registrar_get_list(), which is deprecated")); | ||
68 | warned = 1; | ||
69 | } | ||
70 | return _registrar_get_list (plist); | ||
71 | } | ||
72 | |||
73 | int | ||
74 | registrar_get_iterator (iterator_t *pitr) | ||
75 | { | ||
76 | int status = 0; | ||
77 | if (pitr == NULL) | ||
78 | return MU_ERR_OUT_PTR_NULL; | ||
79 | monitor_wrlock (®istrar_monitor); | ||
80 | if (registrar_list == NULL) | ||
81 | { | ||
82 | status = list_create (®istrar_list); | ||
83 | if (status) | ||
84 | return status; | ||
85 | } | ||
86 | status = list_get_iterator (registrar_list, pitr); | ||
87 | monitor_unlock (®istrar_monitor); | ||
88 | return status; | ||
89 | } | ||
90 | |||
91 | int | ||
92 | registrar_lookup (const char *name, record_t *precord) | ||
93 | { | ||
94 | iterator_t iterator; | ||
95 | int status = registrar_get_iterator (&iterator); | ||
96 | if (status != 0) | ||
97 | return status; | ||
98 | status = MU_ERR_NOENT; | ||
99 | for (iterator_first (iterator); status != 0 && !iterator_is_done (iterator); | ||
100 | iterator_next (iterator)) | ||
101 | { | ||
102 | record_t record; | ||
103 | iterator_current (iterator, (void **)&record); | ||
104 | if (record_is_scheme (record, name)) | ||
105 | { | ||
106 | status = 0; | ||
107 | *precord = record; | ||
108 | } | ||
109 | } | ||
110 | iterator_destroy (&iterator); | ||
111 | return status; | ||
112 | } | ||
113 | |||
114 | |||
115 | static int | ||
116 | _compare_prio (const void *item, const void *value) | ||
117 | { | ||
118 | const record_t a = item; | ||
119 | const record_t b = value; | ||
120 | if (a->priority > b->priority) | ||
121 | return 0; | ||
122 | return -1; | ||
123 | } | ||
124 | |||
56 | int | 125 | int |
57 | registrar_record (record_t record) | 126 | registrar_record (record_t record) |
58 | { | 127 | { |
128 | int status; | ||
59 | list_t list; | 129 | list_t list; |
60 | registrar_get_list (&list); | 130 | list_comparator_t comp; |
61 | return list_append (list, record); | 131 | |
132 | _registrar_get_list (&list); | ||
133 | comp = list_set_comparator (list, _compare_prio); | ||
134 | status = list_insert (list, record, record, 1); | ||
135 | if (status == MU_ERR_NOENT) | ||
136 | status = list_append (list, record); | ||
137 | list_set_comparator (list, comp); | ||
138 | return status; | ||
62 | } | 139 | } |
63 | 140 | ||
64 | int | 141 | int |
65 | unregistrar_record (record_t record) | 142 | unregistrar_record (record_t record) |
66 | { | 143 | { |
67 | list_t list; | 144 | list_t list; |
68 | registrar_get_list (&list); | 145 | _registrar_get_list (&list); |
69 | list_remove (list, record); | 146 | list_remove (list, record); |
70 | return 0; | 147 | return 0; |
71 | } | 148 | } | ... | ... |
-
Please register or sign in to post a comment