Copyright updates:
[exim.git] / src / src / lookups / ibase.c
index 5ae966611a9bc8e44168deab7ee850e0a7488b39..34a714dc3dbb234d07b4f2fc8acccfa2c9f9745f 100644 (file)
@@ -3,6 +3,7 @@
 *************************************************/
 
 /* Copyright (c) University of Cambridge 1995 - 2018 */
+/* Copyright (c) The Exim Maintainers 2020 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 /* The code in this module was contributed by Ard Biesheuvel. */
@@ -31,9 +32,9 @@ static ibase_connection *ibase_connections = NULL;
 
 /* See local README for interface description. */
 
-static void *ibase_open(uschar * filename, uschar ** errmsg)
+static void *ibase_open(const uschar * filename, uschar ** errmsg)
 {
-    return (void *) (1);        /* Just return something non-null */
+return (void *) (1);        /* Just return something non-null */
 }
 
 
@@ -51,7 +52,7 @@ static void ibase_tidy(void)
 
     while ((cn = ibase_connections) != NULL) {
         ibase_connections = cn->next;
-        DEBUG(D_lookup) debug_printf("close Interbase connection: %s\n",
+        DEBUG(D_lookup) debug_printf_indent("close Interbase connection: %s\n",
                                      cn->server);
         isc_commit_transaction(status, &cn->transh);
         isc_detach_database(status, &cn->dbh);
@@ -113,6 +114,7 @@ isc_stmt_handle stmth = NULL;
 XSQLDA *out_sqlda;
 XSQLVAR *var;
 int i;
+rmark reset_point;
 
 char buffer[256];
 ISC_STATUS status[20], *statusp = status;
@@ -170,14 +172,12 @@ if (cn)
     isc_detach_database(status, &cn->dbh);
     }
   else
-    {
-    DEBUG(D_lookup) debug_printf("Interbase using cached connection for %s\n",
+    DEBUG(D_lookup) debug_printf_indent("Interbase using cached connection for %s\n",
                     server_copy);
-    }
   }
 else
   {
-  cn = store_get(sizeof(ibase_connection));
+  cn = store_get(sizeof(ibase_connection), FALSE);
   cn->server = server_copy;
   cn->dbh = NULL;
   cn->transh = NULL;
@@ -210,7 +210,7 @@ if (cn->dbh == NULL || cn->transh == NULL)
   dpb_length = dpb - buffer;
 
   DEBUG(D_lookup)
-      debug_printf("new Interbase connection: database=%s user=%s\n",
+      debug_printf_indent("new Interbase connection: database=%s user=%s\n",
                   sdata[0], sdata[1]);
 
   /* Connect to the database */
@@ -250,7 +250,9 @@ if (isc_dsql_allocate_statement(status, &cn->dbh, &stmth))
   goto IBASE_EXIT;
   }
 
-out_sqlda = store_get(XSQLDA_LENGTH(1));
+/* Lacking any information, assume that the data is untainted */
+reset_point = store_mark();
+out_sqlda = store_get(XSQLDA_LENGTH(1), FALSE);
 out_sqlda->version = SQLDA_VERSION1;
 out_sqlda->sqln = 1;
 
@@ -258,7 +260,7 @@ if (isc_dsql_prepare
     (status, &cn->transh, &stmth, 0, query, 1, out_sqlda))
   {
   isc_interprete(buffer, &statusp);
-  store_reset(out_sqlda);
+  reset_point = store_reset(reset_point);
   out_sqlda = NULL;
   *errmsg =
       string_sprintf("Interbase prepare_statement() failed: %s",
@@ -270,13 +272,13 @@ if (isc_dsql_prepare
 /* re-allocate the output structure if there's more than one field */
 if (out_sqlda->sqln < out_sqlda->sqld)
   {
-  XSQLDA *new_sqlda = store_get(XSQLDA_LENGTH(out_sqlda->sqld));
+  XSQLDA *new_sqlda = store_get(XSQLDA_LENGTH(out_sqlda->sqld), FALSE);
   if (isc_dsql_describe
       (status, &stmth, out_sqlda->version, new_sqlda))
     {
     isc_interprete(buffer, &statusp);
     isc_dsql_free_statement(status, &stmth, DSQL_drop);
-    store_reset(out_sqlda);
+    reset_point = store_reset(reset_point);
     out_sqlda = NULL;
     *errmsg = string_sprintf("Interbase describe_statement() failed: %s",
                       buffer);
@@ -292,46 +294,46 @@ for (i = 0, var = out_sqlda->sqlvar; i < out_sqlda->sqld; i++, var++)
   switch (var->sqltype & ~1)
     {
     case SQL_VARYING:
-       var->sqldata = CS store_get(sizeof(char) * var->sqllen + 2);
+       var->sqldata = CS store_get(sizeof(char) * var->sqllen + 2, FALSE);
        break;
     case SQL_TEXT:
-       var->sqldata = CS store_get(sizeof(char) * var->sqllen);
+       var->sqldata = CS store_get(sizeof(char) * var->sqllen, FALSE);
        break;
     case SQL_SHORT:
-       var->sqldata = CS  store_get(sizeof(short));
+       var->sqldata = CS  store_get(sizeof(short), FALSE);
        break;
     case SQL_LONG:
-       var->sqldata = CS  store_get(sizeof(ISC_LONG));
+       var->sqldata = CS  store_get(sizeof(ISC_LONG), FALSE);
        break;
 #ifdef SQL_INT64
     case SQL_INT64:
-       var->sqldata = CS  store_get(sizeof(ISC_INT64));
+       var->sqldata = CS  store_get(sizeof(ISC_INT64), FALSE);
        break;
 #endif
     case SQL_FLOAT:
-       var->sqldata = CS  store_get(sizeof(float));
+       var->sqldata = CS  store_get(sizeof(float), FALSE);
        break;
     case SQL_DOUBLE:
-       var->sqldata = CS  store_get(sizeof(double));
+       var->sqldata = CS  store_get(sizeof(double), FALSE);
        break;
 #ifdef SQL_TIMESTAMP
     case SQL_DATE:
-       var->sqldata = CS  store_get(sizeof(ISC_QUAD));
+       var->sqldata = CS  store_get(sizeof(ISC_QUAD), FALSE);
        break;
 #else
     case SQL_TIMESTAMP:
-       var->sqldata = CS  store_get(sizeof(ISC_TIMESTAMP));
+       var->sqldata = CS  store_get(sizeof(ISC_TIMESTAMP), FALSE);
        break;
     case SQL_TYPE_DATE:
-       var->sqldata = CS  store_get(sizeof(ISC_DATE));
+       var->sqldata = CS  store_get(sizeof(ISC_DATE), FALSE);
        break;
     case SQL_TYPE_TIME:
-       var->sqldata = CS  store_get(sizeof(ISC_TIME));
+       var->sqldata = CS  store_get(sizeof(ISC_TIME), FALSE);
        break;
   #endif
     }
   if (var->sqltype & 1)
-    var->sqlind = (short *) store_get(sizeof(short));
+    var->sqlind = (short *) store_get(sizeof(short), FALSE);
   }
 
 /* finally, we're ready to execute the statement */
@@ -413,7 +415,7 @@ if (!result)
   *errmsg = US "Interbase: no data found";
   }
 else
-  store_reset(result->s + result->ptr + 1);
+  gstring_release_unused(result);
 
 
 /* Get here by goto from various error checks. */
@@ -432,7 +434,7 @@ if (result)
   }
 else
   {
-  DEBUG(D_lookup) debug_printf("%s\n", *errmsg);
+  DEBUG(D_lookup) debug_printf_indent("%s\n", *errmsg);
   return yield;           /* FAIL or DEFER */
   }
 }
@@ -449,33 +451,31 @@ arguments are not used. Loop through a list of servers while the query is
 deferred with a retryable error. */
 
 static int
-ibase_find(void *handle, uschar * filename, uschar * query, int length,
-           uschar ** result, uschar ** errmsg, uint *do_cache)
+ibase_find(void * handle, const uschar * filename, uschar * query, int length,
+  uschar ** result, uschar ** errmsg, uint * do_cache, const uschar * opts)
 {
-    int sep = 0;
-    uschar *server;
-    uschar *list = ibase_servers;
-    uschar buffer[512];
-
-    /* Keep picky compilers happy */
-    do_cache = do_cache;
-
-    DEBUG(D_lookup) debug_printf("Interbase query: %s\n", query);
-
-    while ((server =
-            string_nextinlist(&list, &sep, buffer,
-                              sizeof(buffer))) != NULL) {
-        BOOL defer_break = FALSE;
-        int rc = perform_ibase_search(query, server, result, errmsg,
-                                      &defer_break);
-        if (rc != DEFER || defer_break)
-            return rc;
-    }
+int sep = 0;
+uschar *server;
+uschar *list = ibase_servers;
+uschar buffer[512];
 
-    if (ibase_servers == NULL)
-        *errmsg = US "no Interbase servers defined (ibase_servers option)";
+/* Keep picky compilers happy */
+do_cache = do_cache;
 
-    return DEFER;
+DEBUG(D_lookup) debug_printf_indent("Interbase query: %s\n", query);
+
+while ((server = string_nextinlist(&list, &sep, buffer, sizeof(buffer))))
+  {
+  BOOL defer_break = FALSE;
+  int rc = perform_ibase_search(query, server, result, errmsg, &defer_break);
+  if (rc != DEFER || defer_break)
+    return rc;
+  }
+
+if (!ibase_servers)
+  *errmsg = US "no Interbase servers defined (ibase_servers option)";
+
+return DEFER;
 }
 
 
@@ -516,7 +516,7 @@ static uschar *ibase_quote(uschar * s, uschar * opt)
 
     if (count == 0)
         return s;
-    t = quoted = store_get(Ustrlen(s) + count + 1);
+    t = quoted = store_get(Ustrlen(s) + count + 1, FALSE);
 
     while ((c = *s++) != 0) {
         if (Ustrchr("'", c) != NULL) {
@@ -562,15 +562,15 @@ fprintf(f, "Library version: ibase: Exim version %s\n", EXIM_VERSION_STR);
 
 
 static lookup_info _lookup_info = {
-  US"ibase",                     /* lookup name */
-  lookup_querystyle,             /* query-style lookup */
-  ibase_open,                    /* open function */
-  NULL,                          /* no check function */
-  ibase_find,                    /* find function */
-  NULL,                          /* no close function */
-  ibase_tidy,                    /* tidy function */
-  ibase_quote,                   /* quoting function */
-  ibase_version_report           /* version reporting */
+  .name = US"ibase",                   /* lookup name */
+  .type = lookup_querystyle,           /* query-style lookup */
+  .open = ibase_open,                  /* open function */
+  .check NULL,                         /* no check function */
+  .find = ibase_find,                  /* find function */
+  .close = NULL,                       /* no close function */
+  .tidy = ibase_tidy,                  /* tidy function */
+  .quote = ibase_quote,                        /* quoting function */
+  .version_report = ibase_version_report           /* version reporting */
 };
 
 #ifdef DYNLOOKUP