diff mbox series

[3/5] provisiondb: Correct the precondition return conditions of 'tags_match'.

Message ID dda4411f6c7fee423770b046b696a7596e0edeca.1738800116.git.gerickson@nuovations.com (mailing list archive)
State Under Review
Headers show
Series Correct Provisioning Database Tags Matching Behavior | expand

Commit Message

Grant Erickson Feb. 6, 2025, 12:34 a.m. UTC
Prior to this change, specifying 'TagsFilter' in
${sysconfdir}/ofono/main.conf resulted in returning APNs which have no
tags plus APNs that match a tag in 'TagsFilter'. In addition to
seemingly violating the rule of least astonishment, this did not do
what was desired, which was to downselect more than one APN to one (or
more) matching a specific tag.

With this change, specifying 'TagsFilter' now follows the rule of
least astonishment and matches expectations, returning only those APNs
which match a tag in 'TagsFilter', period.

One specific tag:

    # ./lookup-apn -t "kore-m2m-public" 311 480
    Opening database in default location
    Searching for info for network: 311480, spn: <None>
    Name: 4G LTE Contract (Public)
    APN: vzwinternet
    Type: 1
    Proto: 2
    Tags: kore-m2m-public

As desired / expected.

Another specific tag:

    # ./lookup-apn -t "kore-m2m-private" 311 480
    Opening database in default location
    Searching for info for network: 311480, spn: <None>
    Name: 4G LTE Contract (Private)
    APN: wyleslte.gw7.vzwentp
    Type: 1
    Proto: 2
    Tags: kore-m2m-private

As desired / expected.

Two specific tags:

    # ./lookup-apn -t "kore-m2m-private,kore-m2m-public" 311 480
    Opening database in default location
    Searching for info for network: 311480, spn: <None>
    Name: 4G LTE Contract (Public)
    APN: vzwinternet
    Type: 1
    Proto: 2
    Tags: kore-m2m-public

    Name: 4G LTE Contract (Private)
    APN: wyleslte.gw7.vzwentp
    Type: 1
    Proto: 2
    Tags: kore-m2m-private

As desired / expected.

No tags:

    # ./lookup-apn 311 480
    Opening database in default location
    Searching for info for network: 311480, spn: <None>
    Name: 4G LTE Contract
    APN: vzwims
    Type: 28
    Proto: 2
    Tags: (null)

    Name: 4G LTE Contract (Public)
    APN: vzwinternet
    Type: 1
    Proto: 2
    Tags: kore-m2m-public

    Name: 4G LTE Contract (Private)
    APN: wyleslte.gw7.vzwentp
    Type: 1
    Proto: 2
    Tags: kore-m2m-private

    Name: 4G LTE Contract
    APN: vzwapp
    Type: 4
    Proto: 2
    Tags: (null)

As desired / expected.
---
 src/provisiondb.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/provisiondb.c b/src/provisiondb.c
index 4a7f1bb6ef6e..753d7725103a 100644
--- a/src/provisiondb.c
+++ b/src/provisiondb.c
@@ -224,9 +224,22 @@  static bool tags_match(char **tags_filter, const char *tags)
 	_auto_(l_strv_free) char **split_tags = 0;
 	unsigned int i;
 
-	if (!tags_filter || !tags)
+	/*
+	 * If tags_filter was not specified, then the caller does not want
+	 * to match on tags, so just return true.
+	 */
+	if (!tags_filter)
 		return true;
 
+	/*
+	 * If tags_filter was specified, then the caller does want to
+	 * match on tags. Consequently, if there are no tags to match
+	 * against, then we must return false since such an entry cannot
+	 * match.
+	 */
+	if (tags_filter && !tags)
+		return false;
+
 	split_tags = l_strsplit(tags, ',');
 
 	for (i = 0; tags_filter[i]; i++)