466
*exactusermatch = usermatched;
467
return pathmatchlen;
468
}
469
+
470
+int urlmatch_config_entry(const char *var, const char *value, void *cb)
471
+{
472
+ struct string_list_item *item;
473
+ struct urlmatch_config *collect = cb;
474
+ struct urlmatch_item *matched;
475
+ struct url_info *url = &collect->url;
476
+ const char *key, *dot;
477
+ struct strbuf synthkey = STRBUF_INIT;
478
+ size_t matched_len = 0;
479
+ int user_matched = 0;
480
+ int retval;
481
+
482
+ key = skip_prefix(var, collect->section);
483
+ if (!key || *(key++) != '.') {
484
+ if (collect->cascade_fn)
485
+ return collect->cascade_fn(var, value, cb);
486
+ return 0; /* not interested */
487
+ }
488
+ dot = strrchr(key, '.');
489
+ if (dot) {
490
+ char *config_url, *norm_url;
491
+ struct url_info norm_info;
492
+
493
+ config_url = xmemdupz(key, dot - key);
494
+ norm_url = url_normalize(config_url, &norm_info);
495
+ free(config_url);
496
+ if (!norm_url)
497
+ return 0;
498
+ matched_len = match_urls(url, &norm_info, &user_matched);
499
+ free(norm_url);
500
+ if (!matched_len)
501
+ return 0;
502
+ key = dot + 1;
503
+ }
504
+
505
+ if (collect->key && strcmp(key, collect->key))
506
+ return 0;
507
+
508
+ item = string_list_insert(&collect->vars, key);
509
+ if (!item->util) {
510
+ matched = xcalloc(1, sizeof(*matched));
511
+ item->util = matched;
512
+ } else {
513
+ matched = item->util;
514
+ /*
515
+ * Is our match shorter? Is our match the same
516
+ * length, and without user while the current
517
+ * candidate is with user? Then we cannot use it.
518
+ */
519
+ if (matched_len < matched->matched_len ||
520
+ ((matched_len == matched->matched_len) &&
521
+ (!user_matched && matched->user_matched)))
522
+ return 0;
523
+ /* Otherwise, replace it with this one. */
524
+ }
525
+
526
+ matched->matched_len = matched_len;
527
+ matched->user_matched = user_matched;
528
+ strbuf_addstr(&synthkey, collect->section);
529
+ strbuf_addch(&synthkey, '.');
530
+ strbuf_addstr(&synthkey, key);
531
+ retval = collect->collect_fn(synthkey.buf, value, collect->cb);
532
+
533
+ strbuf_release(&synthkey);
534
+ return retval;
535
+}