+ // Create a domains settings map.
+ QMap<QString, int> domainSettingsMap;
+
+ // Populate the domain settings map.
+ while (allDomainNamesQuery.next())
+ {
+ // Add the domain name and database ID to the map.
+ domainSettingsMap.insert(allDomainNamesQuery.record().field(DomainsDatabaseHelper::DOMAIN_NAME).value().toString(),
+ allDomainNamesQuery.record().field(DomainsDatabaseHelper::_ID).value().toInt());
+ }
+
+ // Initialize the database ID tracker.
+ int databaseId = -1;
+
+ // Get the database ID if the hostname is found in the domain settings set.
+ if (domainSettingsMap.contains(hostname))
+ {
+ databaseId = domainSettingsMap.value(hostname);
+ }
+
+ // Create a subdomain string.
+ QString subdomain = hostname;
+
+ // Check all the subdomains of the hostname.
+ while ((databaseId == -1) && subdomain.contains(".")) // Stop checking when a match is found or there are no more `.` in the hostname.
+ {
+ // Check to see if the domain settings map contains the subdomain with a `*.` prepended.
+ if (domainSettingsMap.contains("*." + subdomain))
+ {
+ // Get the database ID.
+ databaseId = domainSettingsMap.value("*." + subdomain);
+ }
+
+ // Strip out the first subdomain.
+ subdomain = subdomain.section('.', 1);
+ }
+
+ // Instantiate the domain lookup query.
+ QSqlQuery domainLookupQuery(domainsDatabase);