diff options
Diffstat (limited to 'libmailutils/base/registrar.c')
-rw-r--r-- | libmailutils/base/registrar.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/libmailutils/base/registrar.c b/libmailutils/base/registrar.c index e25e6d810..debac377d 100644 --- a/libmailutils/base/registrar.c +++ b/libmailutils/base/registrar.c | |||
@@ -446,3 +446,66 @@ mu_registrar_apply_filter (int (*flt) (mu_record_t, void *), void *data) | |||
446 | mu_monitor_unlock (®istrar_monitor); | 446 | mu_monitor_unlock (®istrar_monitor); |
447 | return 0; | 447 | return 0; |
448 | } | 448 | } |
449 | |||
450 | struct match_closure | ||
451 | { | ||
452 | mu_url_t url; | ||
453 | int flags; | ||
454 | int err; | ||
455 | }; | ||
456 | |||
457 | static int | ||
458 | select_match (void **itmv, size_t itmc, void *call_data) | ||
459 | { | ||
460 | struct match_closure *mc = call_data; | ||
461 | int rc = mu_record_is_scheme (itmv[0], mc->url, mc->flags); | ||
462 | if (rc) | ||
463 | { | ||
464 | struct mu_record_match *match = malloc (sizeof (*match)); | ||
465 | if (!match) | ||
466 | { | ||
467 | mc->err = errno; | ||
468 | return MU_LIST_MAP_STOP; | ||
469 | } | ||
470 | match->record = itmv[0]; | ||
471 | match->flags = rc; | ||
472 | itmv[0] = match; | ||
473 | return MU_LIST_MAP_OK; | ||
474 | } | ||
475 | return MU_LIST_MAP_SKIP; | ||
476 | } | ||
477 | |||
478 | /* Select records matching pathname NAME with given FLAGS | ||
479 | (MU_FOLDER_ATTRIBUTE_* bitmask). On success, store each | ||
480 | match as a pointer to struct mu_record_match in *RET. | ||
481 | */ | ||
482 | int | ||
483 | mu_registrar_match_records (char const *name, int flags, mu_list_t *ret) | ||
484 | { | ||
485 | int rc; | ||
486 | struct match_closure mc; | ||
487 | mu_list_t lst; | ||
488 | |||
489 | rc = mu_url_create (&mc.url, name); | ||
490 | if (rc) | ||
491 | return rc; | ||
492 | mc.flags = flags; | ||
493 | mc.err = 0; | ||
494 | |||
495 | mu_monitor_wrlock (®istrar_monitor); | ||
496 | rc = mu_list_map (registrar_list, select_match, &mc, 1, &lst); | ||
497 | mu_monitor_unlock (®istrar_monitor); | ||
498 | mu_url_destroy (&mc.url); | ||
499 | if (rc == 0) | ||
500 | { | ||
501 | mu_list_set_destroy_item (lst, mu_list_free_item); | ||
502 | if (mc.err) | ||
503 | { | ||
504 | mu_list_destroy (&lst); | ||
505 | rc = mc.err; | ||
506 | } | ||
507 | } | ||
508 | if (rc == 0) | ||
509 | *ret = lst; | ||
510 | return rc; | ||
511 | } | ||