Commit 8ad5ecbc 8ad5ecbc640a04f0eee7f113119d3c58ed362e4c by Sergey Poznyakoff

Find best matching registrar records.

* mailbox/registrar.c (mu_registrar_lookup_url): Find best matching
record.
1 parent cf7af0e1
......@@ -161,6 +161,8 @@ mu_registrar_lookup_url (mu_url_t url, int flags,
mu_record_t *precord, int *pflags)
{
mu_iterator_t iterator;
mu_record_t last_record = NULL;
int last_flags = 0;
int status = mu_registrar_get_iterator (&iterator);
if (status != 0)
return status;
......@@ -173,19 +175,32 @@ mu_registrar_lookup_url (mu_url_t url, int flags,
mu_iterator_current (iterator, (void **)&record);
if ((rc = mu_record_is_scheme (record, url, flags)))
{
if (rc == flags)
{
status = 0;
if (precord)
*precord = record;
if (pflags)
*pflags = rc;
last_record = record;
last_flags = rc;
break;
}
else if (rc > last_flags)
{
status = 0;
last_record = record;
last_flags = rc;
}
}
}
mu_iterator_destroy (&iterator);
if (status &&
/*s FIXME: This check is not enough. */
!mu_is_proto (mu_url_to_string (url))
if (status == 0)
{
if (precord)
*precord = last_record;
if (pflags)
*pflags = last_flags;
}
else if (!mu_is_proto (mu_url_to_string (url)) /* FIXME: This check is not
enough. */
&& mu_registrar_get_default_record (precord) == 0)
{
status = 0;
......