diff options
author | Sean Bright <sean.bright@gmail.com> | 2017-02-21 11:47:41 -0500 |
---|---|---|
committer | Sean Bright <sean.bright@gmail.com> | 2017-02-22 10:22:54 -0600 |
commit | 15ed7af0278f459c69b0d0fd9168e3bc34ccb6a2 (patch) | |
tree | ca438e468aa07f180680611884ca97f2f281f833 /pbx | |
parent | afcdadcd19a118d97bfaab38c14117bd2ff6fd0b (diff) |
pbx_realtime: Prevent premature extension matching
The patterns provided by pbx_realtime were checked in the order in
which they were returned from the realtime backend. If there was
overlap between multiple patterns, the first one to correctly match was
chosen even though it may not have been the best match.
We now sort the patterns descending by their length and compare in that
order. There may be cases where this still results in a sub-optimal
match, but this patch should improve the overall behavior.
ASTERISK-18271 #close
Reported by: Charlie Smurthwaite
Change-Id: I56d9ac15810eb1775966b669c3028e32cc7bd809
Diffstat (limited to 'pbx')
-rw-r--r-- | pbx/pbx_realtime.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/pbx/pbx_realtime.c b/pbx/pbx_realtime.c index 6f5d13738..10a147b14 100644 --- a/pbx/pbx_realtime.c +++ b/pbx/pbx_realtime.c @@ -141,6 +141,13 @@ static void *cleanup(void *unused) return NULL; } +static int extension_length_comparator(struct ast_category *p, struct ast_category *q) +{ + const char *extenp = S_OR(ast_variable_find(p, "exten"), ""); + const char *extenq = S_OR(ast_variable_find(q, "exten"), ""); + + return strlen(extenp) - strlen(extenq); +} /* Realtime switch looks up extensions in the supplied realtime table. @@ -191,6 +198,9 @@ static struct ast_variable *realtime_switch_common(const char *table, const char if (cfg) { char *cat = NULL; + /* Sort so that longer patterns are checked first */ + ast_config_sort_categories(cfg, 1, extension_length_comparator); + while ((cat = ast_category_browse(cfg, cat))) { const char *realtime_exten = ast_variable_retrieve(cfg, cat, "exten"); |