Commit 3b42a3a5 3b42a3a50217575fee4d222204f53e786eb35965 by Sergey Poznyakoff

Swap precedences of MH and Maildir to help in format autodetection

* include/mailutils/registrar.h: Swap MU_MAILDIR_PRIO and
MU_MH_PRIO
(mu_record_is_local)
(mu_registrar_apply_filter): New protos.
* libmailutils/base/registrar.c (mu_registrar_set_default_scheme): Use
mu_registrar_set_default_record.
(mu_record_is_local): New function.
(mu_record_get_url): Use it.
(mu_registrar_apply_filter): New function.
1 parent 259efd34
...@@ -75,7 +75,10 @@ int mu_registrar_lookup_url (mu_url_t url, int flags, ...@@ -75,7 +75,10 @@ int mu_registrar_lookup_url (mu_url_t url, int flags,
75 mu_record_t *precord, int *pflags); 75 mu_record_t *precord, int *pflags);
76 int mu_registrar_record (mu_record_t); 76 int mu_registrar_record (mu_record_t);
77 int mu_unregistrar_record (mu_record_t); 77 int mu_unregistrar_record (mu_record_t);
78 int mu_registrar_apply_filter (int (*flt) (mu_record_t, void *), void *data);
78 79
80 int mu_record_is_local (mu_record_t);
81
79 /* Scheme. */ 82 /* Scheme. */
80 int mu_record_is_scheme (mu_record_t, mu_url_t, int flags); 83 int mu_record_is_scheme (mu_record_t, mu_url_t, int flags);
81 84
...@@ -113,8 +116,8 @@ extern mu_record_t mu_maildir_record; ...@@ -113,8 +116,8 @@ extern mu_record_t mu_maildir_record;
113 #define MU_IMAP_PRIO 100 116 #define MU_IMAP_PRIO 100
114 #define MU_POP_PRIO 200 117 #define MU_POP_PRIO 200
115 #define MU_MBOX_PRIO 300 118 #define MU_MBOX_PRIO 300
116 #define MU_MH_PRIO 400 119 #define MU_MAILDIR_PRIO 400
117 #define MU_MAILDIR_PRIO 500 120 #define MU_MH_PRIO 500
118 #define MU_NNTP_PRIO 600 121 #define MU_NNTP_PRIO 600
119 #define MU_PATH_PRIO 1000 122 #define MU_PATH_PRIO 1000
120 123
......
...@@ -70,12 +70,12 @@ mu_registrar_set_default_scheme (const char *scheme) ...@@ -70,12 +70,12 @@ mu_registrar_set_default_scheme (const char *scheme)
70 70
71 status = mu_registrar_lookup_scheme (scheme, &rec); 71 status = mu_registrar_lookup_scheme (scheme, &rec);
72 if (status == 0) 72 if (status == 0)
73 mu_default_record = rec; 73 mu_registrar_set_default_record (rec);
74 return status; 74 return status;
75 } 75 }
76 76
77 const char * 77 const char *
78 mu_registrar_get_default_scheme () 78 mu_registrar_get_default_scheme (void)
79 { 79 {
80 return mu_default_record ? mu_default_record->scheme : NULL; 80 return mu_default_record ? mu_default_record->scheme : NULL;
81 } 81 }
...@@ -279,6 +279,12 @@ mu_record_is_scheme (mu_record_t record, mu_url_t url, int flags) ...@@ -279,6 +279,12 @@ mu_record_is_scheme (mu_record_t record, mu_url_t url, int flags)
279 } 279 }
280 280
281 int 281 int
282 mu_record_is_local (mu_record_t record)
283 {
284 return record->flags & MU_RECORD_LOCAL;
285 }
286
287 int
282 mu_record_get_url (mu_record_t record, int (*(*_purl)) (mu_url_t)) 288 mu_record_get_url (mu_record_t record, int (*(*_purl)) (mu_url_t))
283 { 289 {
284 if (record == NULL) 290 if (record == NULL)
...@@ -393,6 +399,30 @@ mu_registrar_test_local_url (mu_url_t url, int *pres) ...@@ -393,6 +399,30 @@ mu_registrar_test_local_url (mu_url_t url, int *pres)
393 rc = mu_registrar_lookup_url (url, MU_FOLDER_ATTRIBUTE_ALL, &rec, NULL); 399 rc = mu_registrar_lookup_url (url, MU_FOLDER_ATTRIBUTE_ALL, &rec, NULL);
394 if (rc) 400 if (rc)
395 return rc; 401 return rc;
396 *pres = rec->flags & MU_RECORD_LOCAL; 402 *pres = mu_record_is_local (rec);
403 return 0;
404 }
405
406 /* Apply flt to each record in the registry and remove those, for which it
407 returns non-zero. */
408 int
409 mu_registrar_apply_filter (int (*flt) (mu_record_t, void *), void *data)
410 {
411 mu_iterator_t iterator;
412
413 int status = mu_registrar_get_iterator (&iterator);
414 if (status != 0)
415 return status;
416 mu_monitor_wrlock (&registrar_monitor);
417 for (mu_iterator_first (iterator); !mu_iterator_is_done (iterator);
418 mu_iterator_next (iterator))
419 {
420 mu_record_t record;
421 mu_iterator_current (iterator, (void **)&record);
422 if (flt (record, data))
423 mu_list_remove (registrar_list, record);
424 }
425 mu_iterator_destroy (&iterator);
426 mu_monitor_unlock (&registrar_monitor);
397 return 0; 427 return 0;
398 } 428 }
......