Commit 3bcd7814 3bcd7814cfd629bccc4814e34de5cd3e1982a619 by Sergey Poznyakoff

(mailer_create): Rewritten using registrar_lookup()

1 parent 014fc925
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
...@@ -82,16 +82,7 @@ mailer_get_url_default (const char **url) ...@@ -82,16 +82,7 @@ mailer_get_url_default (const char **url)
82 int 82 int
83 mailer_create (mailer_t * pmailer, const char *name) 83 mailer_create (mailer_t * pmailer, const char *name)
84 { 84 {
85 int status = EINVAL; 85 record_t record;
86 url_t url = NULL;
87 mailer_t mailer = NULL;
88
89 record_t record = NULL;
90 int (*m_init) __P ((mailer_t)) = NULL;
91 int (*u_init) __P ((url_t)) = NULL;
92 list_t list = NULL;
93 iterator_t iterator;
94 int found = 0;
95 86
96 if (pmailer == NULL) 87 if (pmailer == NULL)
97 return MU_ERR_OUT_PTR_NULL; 88 return MU_ERR_OUT_PTR_NULL;
...@@ -99,37 +90,26 @@ mailer_create (mailer_t * pmailer, const char *name) ...@@ -99,37 +90,26 @@ mailer_create (mailer_t * pmailer, const char *name)
99 if (name == NULL) 90 if (name == NULL)
100 mailer_get_url_default (&name); 91 mailer_get_url_default (&name);
101 92
102 registrar_get_list (&list); 93 if (registrar_lookup (name, &record) == 0)
103 status = list_get_iterator (list, &iterator);
104 if (status != 0)
105 return status;
106 for (iterator_first (iterator); !iterator_is_done (iterator);
107 iterator_next (iterator))
108 {
109 iterator_current (iterator, (void **) &record);
110 if (record_is_scheme (record, name))
111 { 94 {
95 int (*m_init) __P ((mailer_t)) = NULL;
96 int (*u_init) __P ((url_t)) = NULL;
97
112 record_get_mailer (record, &m_init); 98 record_get_mailer (record, &m_init);
113 record_get_url (record, &u_init); 99 record_get_url (record, &u_init);
114 if (m_init && u_init) 100 if (m_init && u_init)
115 { 101 {
116 found = 1; 102 int status;
117 break; 103 url_t url;
118 } 104 mailer_t mailer;
119 }
120 }
121 iterator_destroy (&iterator);
122
123 if (!found)
124 return MU_ERR_MAILER_BAD_URL;
125 105
126 /* Allocate memory for mailer. */ 106 /* Allocate memory for mailer. */
127 mailer = calloc (1, sizeof (*mailer)); 107 mailer = calloc (1, sizeof (*mailer));
128 if (mailer == NULL) 108 if (mailer == NULL)
129 return ENOMEM; 109 return ENOMEM;
130 110
131 status = monitor_create (&(mailer->monitor), 0, mailer); 111 status = monitor_create (&mailer->monitor, 0, mailer);
132 if (status != 0) 112 if (status)
133 { 113 {
134 mailer_destroy (&mailer); 114 mailer_destroy (&mailer);
135 return status; 115 return status;
...@@ -137,7 +117,8 @@ mailer_create (mailer_t * pmailer, const char *name) ...@@ -137,7 +117,8 @@ mailer_create (mailer_t * pmailer, const char *name)
137 117
138 /* Parse the url, it may be a bad one and we should bail out if this 118 /* Parse the url, it may be a bad one and we should bail out if this
139 failed. */ 119 failed. */
140 if ((status = url_create (&url, name)) != 0 || (status = u_init (url)) != 0) 120 if ((status = url_create (&url, name)) != 0
121 || (status = u_init (url)) != 0)
141 { 122 {
142 mailer_destroy (&mailer); 123 mailer_destroy (&mailer);
143 return status; 124 return status;
...@@ -145,14 +126,16 @@ mailer_create (mailer_t * pmailer, const char *name) ...@@ -145,14 +126,16 @@ mailer_create (mailer_t * pmailer, const char *name)
145 mailer->url = url; 126 mailer->url = url;
146 127
147 status = m_init (mailer); 128 status = m_init (mailer);
148 if (status != 0) 129 if (status)
149 {
150 mailer_destroy (&mailer); 130 mailer_destroy (&mailer);
151 }
152 else 131 else
153 *pmailer = mailer; 132 *pmailer = mailer;
154 133
155 return status; 134 return status;
135 }
136 }
137
138 return MU_ERR_MAILER_BAD_URL;
156 } 139 }
157 140
158 void 141 void
......