575
ACCEPT_ALL
576
};
577
578
+/*
579
+ * Check if a specific field and its advertised value match the local
580
+ * configuration of a given promisor remote.
581
+ *
582
+ * Returns 1 if they match, 0 otherwise.
583
+ */
584
static int match_field_against_config(const char *field, const char *value,
585
struct promisor_info *config_info)
586
{
592
return 0;
593
}
594
595
+/*
596
+ * Check that the advertised fields match the local configuration.
597
+ *
598
+ * When 'config_entry' is NULL (ACCEPT_ALL mode), every checked field
599
+ * must match at least one remote in 'config_info'.
600
+ *
601
+ * When 'config_entry' points to a specific remote's config, the
602
+ * checked fields are compared against that single remote only.
603
+ */
604
static int all_fields_match(struct promisor_info *advertised,
605
struct string_list *config_info,
591
- int in_list)
606
+ struct promisor_info *config_entry)
607
{
608
struct string_list *fields = fields_checked();
609
struct string_list_item *item_checked;
612
int match = 0;
613
const char *field = item_checked->string;
614
const char *value = NULL;
600
- struct string_list_item *item;
615
616
if (!strcasecmp(field, promisor_field_filter))
617
value = advertised->filter;
621
if (!value)
622
return 0;
623
610
- if (in_list) {
624
+ if (config_entry) {
625
+ match = match_field_against_config(field, value,
626
+ config_entry);
627
+ } else {
628
+ struct string_list_item *item;
629
for_each_string_list_item(item, config_info) {
630
struct promisor_info *p = item->util;
631
if (match_field_against_config(field, value, p)) {
633
break;
634
}
635
}
618
- } else {
619
- item = string_list_lookup(config_info, advertised->name);
620
- if (item) {
621
- struct promisor_info *p = item->util;
622
- match = match_field_against_config(field, value, p);
623
- }
636
}
637
638
if (!match)
652
const char *remote_url = advertised->url;
653
654
if (accept == ACCEPT_ALL)
643
- return all_fields_match(advertised, config_info, 1);
655
+ return all_fields_match(advertised, config_info, NULL);
656
657
/* Get config info for that promisor remote */
658
item = string_list_lookup(config_info, remote_name);
664
p = item->util;
665
666
if (accept == ACCEPT_KNOWN_NAME)
655
- return all_fields_match(advertised, config_info, 0);
667
+ return all_fields_match(advertised, config_info, p);
668
669
if (accept != ACCEPT_KNOWN_URL)
670
BUG("Unhandled 'enum accept_promisor' value '%d'", accept);
675
}
676
677
if (!strcmp(p->url, remote_url))
666
- return all_fields_match(advertised, config_info, 0);
678
+ return all_fields_match(advertised, config_info, p);
679
680
warning(_("known remote named '%s' but with URL '%s' instead of '%s'"),
681
remote_name, p->url, remote_url);