[exim-cvs] Refactor lookup argument shuffling

Startseite
Nachricht löschen
Nachricht beantworten
Autor: Exim Git Commits Mailing List
Datum:  
To: exim-cvs
Betreff: [exim-cvs] Refactor lookup argument shuffling
Gitweb: https://git.exim.org/exim.git/commitdiff/4a7dca52352d0976f200b89a50825433b7551554
Commit:     4a7dca52352d0976f200b89a50825433b7551554
Parent:     46fa6b8a21e141c73c95300537d7e71d545d6e25
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Sat Jun 6 14:45:47 2020 +0100
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Sat Jun 6 15:43:33 2020 +0100


    Refactor lookup argument shuffling
---
 src/src/expand.c    | 20 +++-----------------
 src/src/functions.h |  1 +
 src/src/match.c     | 17 +----------------
 src/src/search.c    | 36 ++++++++++++++++++++++++++++++++++++
 4 files changed, 41 insertions(+), 33 deletions(-)


diff --git a/src/src/expand.c b/src/src/expand.c
index b015124..37be216 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -4390,7 +4390,7 @@ if (is_tainted(string))
goto EXPAND_FAILED;
}

-while (*s != 0)
+while (*s)
   {
   uschar *value;
   uschar name[256];
@@ -4776,7 +4776,7 @@ while (*s != 0)
       int save_expand_nmax =
         save_expand_strings(save_expand_nstring, save_expand_nlength);


-      if ((expand_forbid & RDO_LOOKUP) != 0)
+      if (expand_forbid & RDO_LOOKUP)
         {
         expand_string_message = US"lookup expansions are not permitted";
         goto EXPAND_FAILED;
@@ -4875,21 +4875,7 @@ while (*s != 0)
       file types, the query (i.e. "key") starts with a file name. */


       if (!key)
-        {
-    Uskip_whitespace(&filename);
-        key = filename;
-
-        if (mac_islookup(stype, lookup_querystyle))
-          filename = NULL;
-        else
-          if (*filename == '/')
-        {
-        while (*key && !isspace(*key)) key++;
-        if (*key) *key++ = '\0';
-        }
-      else
-        filename = NULL;
-        }
+    key = search_args(stype, name, filename, &filename);


       /* If skipping, don't do the next bit - just lookup_value == NULL, as if
       the entry was not found. Note that there is no search_close() function.
diff --git a/src/src/functions.h b/src/src/functions.h
index 486a915..e6b78db 100644
--- a/src/src/functions.h
+++ b/src/src/functions.h
@@ -448,6 +448,7 @@ extern void    route_init(void);
 extern gstring * route_show_supported(gstring *);
 extern void    route_tidyup(void);


+extern uschar *search_args(int, uschar *, uschar *, uschar **);
 extern uschar *search_find(void *, const uschar *, uschar *, int,
          const uschar *, int, int, int *, const uschar *);
 extern int     search_findtype(const uschar *, int);
diff --git a/src/src/match.c b/src/src/match.c
index 65d4419..4553741 100644
--- a/src/src/match.c
+++ b/src/src/match.c
@@ -286,22 +286,7 @@ if (!cb->use_partial) partial = -1;


/* Set the parameters for the three different kinds of lookup. */

-keyquery = semicolon + 1;
-Uskip_whitespace(&keyquery);
-
-if (mac_islookup(search_type, lookup_absfilequery))
- {
- filename = keyquery;
- while (*keyquery && !isspace(*keyquery)) keyquery++;
- filename = string_copyn(filename, keyquery - filename);
- Uskip_whitespace(&keyquery);
- }
-
-else if (!mac_islookup(search_type, lookup_querystyle))
- {
- filename = keyquery;
- keyquery = s;
- }
+keyquery = search_args(search_type, s, semicolon+1, &filename);

/* Now do the actual lookup; throw away the data returned unless it was asked
for; partial matching is all handled inside search_find(). Note that there is
diff --git a/src/src/search.c b/src/src/search.c
index d1633a5..061a9e8 100644
--- a/src/src/search.c
+++ b/src/src/search.c
@@ -217,6 +217,42 @@ return stype;
}


+/* Set the parameters for the three different kinds of lookup.
+Arguments:
+ search_type    the search-type code
+ search        the search-type string
+ query        argument for the search; filename or query
+ fnamep        pointer to return filename
+
+Return:    keyquery    the search-type (for single-key) or query (for query-type)
+ */
+uschar *
+search_args(int search_type, uschar * search, uschar * query, uschar ** fnamep)
+{
+Uskip_whitespace(&query);
+if (mac_islookup(search_type, lookup_absfilequery))
+  {                    /* query-style but with file (sqlite) */
+  uschar * s = query;
+  if (*query == '/')
+    {
+    while (*query && !isspace(*query)) query++;
+    *fnamep = string_copyn(s, query - s);
+    Uskip_whitespace(&query);
+    }
+  else
+    *fnamep = NULL;
+  return query;        /* remainder after file skipped */
+  }
+if (!mac_islookup(search_type, lookup_querystyle))
+  {                    /* single-key */
+  *fnamep = query;
+  return search;    /* modifiers important so use "keyquery" for them */
+  }
+*fnamep = NULL;                /* else query-style */
+return query;
+}
+
+


 /*************************************************
 *               Release cached resources         *