C99 initialisers
[exim.git] / src / src / lookups / oracle.c
index bc14def701f5985fbf5f3152da9d1af89975232d..c37503048351abe5285fb75b9125e4e6800560e0 100644 (file)
@@ -196,7 +196,7 @@ return col;
 /* See local README for interface description. */
 
 static void *
-oracle_open(uschar *filename, uschar **errmsg)
+oracle_open(const uschar * filename, uschar ** errmsg)
 {
 return (void *)(1);    /* Just return something non-null */
 }
@@ -216,7 +216,7 @@ oracle_connection *cn;
 while ((cn = oracle_connections) != NULL)
   {
   oracle_connections = cn->next;
-  DEBUG(D_lookup) debug_printf("close ORACLE connection: %s\n", cn->server);
+  DEBUG(D_lookup) debug_printf_indent("close ORACLE connection: %s\n", cn->server);
   ologof(cn->handle);
   }
 }
@@ -254,7 +254,6 @@ Ora_Describe *desc = NULL;
 Ora_Define *def = NULL;
 void *hda = NULL;
 
-int i;
 int yield = DEFER;
 unsigned int num_fields = 0;
 gstring * result = NULL;
@@ -267,7 +266,7 @@ database, user, password. We can write to the string, since it is in a
 nextinlist temporary buffer. The copy of the string that is used for caching
 has the password removed. This copy is also used for debugging output. */
 
-for (i = 3; i > 0; i--)
+for (int i = 3; i > 0; i--)
   {
   uschar *pp = Ustrrchr(server, '/');
   if (pp == NULL)
@@ -301,13 +300,13 @@ for (cn = oracle_connections; cn; cn = cn->next)
 
 if (!cn)
   {
-  DEBUG(D_lookup) debug_printf("ORACLE new connection: host=%s database=%s "
+  DEBUG(D_lookup) debug_printf_indent("ORACLE new connection: host=%s database=%s "
     "user=%s\n", sdata[0], sdata[1], sdata[2]);
 
   /* Get store for a new connection, initialize it, and connect to the server */
 
-   oracle_handle = store_get(sizeof(struct cda_def));
-   hda = store_get(HDA_SIZE);
+   oracle_handle = store_get(sizeof(struct cda_def), FALSE);
+   hda = store_get(HDA_SIZE, FALSE);
    memset(hda,'\0',HDA_SIZE);
 
   /*
@@ -330,7 +329,7 @@ if (!cn)
 
   /* Add the connection to the cache */
 
-  cn = store_get(sizeof(oracle_connection));
+  cn = store_get(sizeof(oracle_connection), FALSE);
   cn->server = server_copy;
   cn->handle = oracle_handle;
   cn->next = oracle_connections;
@@ -344,12 +343,12 @@ to obliterate the password because it is in a nextinlist temporary buffer. */
 else
   {
   DEBUG(D_lookup)
-    debug_printf("ORACLE using cached connection for %s\n", server_copy);
+    debug_printf_indent("ORACLE using cached connection for %s\n", server_copy);
   }
 
 /* We have a connection. Open a cursor and run the query */
 
-cda = store_get(sizeof(Cda_Def));
+cda = store_get(sizeof(Cda_Def), FALSE);
 
 if (oopen(cda, oracle_handle, (text *)0, -1, -1, (text *)0, -1) != 0)
   {
@@ -370,8 +369,8 @@ if (oparse(cda, (text *)query, (sb4) -1,
 /* Find the number of fields returned and sort out their types. If the number
 is one, we don't add field names to the data. Otherwise we do. */
 
-def = store_get(sizeof(Ora_Define)*MAX_SELECT_LIST_SIZE);
-desc = store_get(sizeof(Ora_Describe)*MAX_SELECT_LIST_SIZE);
+def = store_get(sizeof(Ora_Define)*MAX_SELECT_LIST_SIZE, FALSE);
+desc = store_get(sizeof(Ora_Describe)*MAX_SELECT_LIST_SIZE, FALSE);
 
 if ((num_fields = describe_define(cda,def,desc)) == -1)
   {
@@ -404,7 +403,7 @@ while (cda->rc != NO_DATA_FOUND)  /* Loop for each row */
 
   /* Multiple fields - precede by file name, removing {lead,trail}ing WS */
 
-  else for (i = 0; i < num_fields; i++)
+  else for (int i = 0; i < num_fields; i++)
     {
     int slen;
     uschar *s = US desc[i].buf;
@@ -415,15 +414,14 @@ while (cda->rc != NO_DATA_FOUND)  /* Loop for each row */
     result = string_catn(result, s, slen);
     result = string_catn(result, US"=", 1);
 
-    /* int and float type wont ever need escaping. Otherwise, quote the value
+    /* int and float type won't ever need escaping. Otherwise, quote the value
     if it contains spaces or is empty. */
 
     if (desc[i].dbtype != INT_TYPE && desc[i].dbtype != FLOAT_TYPE &&
        (def[i].buf[0] == 0 || strchr(def[i].buf, ' ') != NULL))
       {
-      int j;
       result = string_catn(result, "\"", 1);
-      for (j = 0; j < def[i].col_retlen; j++)
+      for (int j = 0; j < def[i].col_retlen; j++)
         {
         if (def[i].buf[j] == '\"' || def[i].buf[j] == '\\')
           result = string_catn(result, "\\", 1);
@@ -467,7 +465,7 @@ if (!result)
   *errmsg = "ORACLE: no data found";
   }
 else
-  store_reset(result->s + result->ptr + 1);
+  gstring_release_unused(result);
 
 /* Get here by goto from various error checks. */
 
@@ -488,7 +486,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 */
   }
 }
@@ -505,8 +503,8 @@ arguments are not used. Loop through a list of servers while the query is
 deferred with a retryable error. */
 
 static int
-oracle_find(void *handle, uschar *filename, uschar *query, int length,
-  uschar **result, uschar **errmsg, uint *do_cache)
+oracle_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;
@@ -515,16 +513,16 @@ uschar buffer[512];
 
 do_cache = do_cache;   /* Placate picky compilers */
 
-DEBUG(D_lookup) debug_printf("ORACLE query: %s\n", query);
+DEBUG(D_lookup) debug_printf_indent("ORACLE query: %s\n", query);
 
-while ((server = string_nextinlist(&list, &sep, buffer, sizeof(buffer))) != NULL)
+while ((server = string_nextinlist(&list, &sep, buffer, sizeof(buffer))))
   {
   BOOL defer_break;
   int rc = perform_oracle_search(query, server, result, errmsg, &defer_break);
   if (rc != DEFER || defer_break) return rc;
   }
 
-if (oracle_servers == NULL)
+if (!oracle_servers)
   *errmsg = "no ORACLE servers defined (oracle_servers option)";
 
 return DEFER;
@@ -563,7 +561,7 @@ while ((c = *t++) != 0)
   if (strchr("\n\t\r\b\'\"\\", c) != NULL) count++;
 
 if (count == 0) return s;
-t = quoted = store_get((int)strlen(s) + count + 1);
+t = quoted = store_get((int)strlen(s) + count + 1, is_tainted(s));
 
 while ((c = *s++) != 0)
   {
@@ -610,15 +608,15 @@ fprintf(f, "Library version: Oracle: Exim version %s\n", EXIM_VERSION_STR);
 
 
 static lookup_info _lookup_info = {
-  US"oracle",                    /* lookup name */
-  lookup_querystyle,             /* query-style lookup */
-  oracle_open,                   /* open function */
-  NULL,                          /* check function */
-  oracle_find,                   /* find function */
-  NULL,                          /* no close function */
-  oracle_tidy,                   /* tidy function */
-  oracle_quote,                  /* quoting function */
-  oracle_version_report          /* version reporting */
+  .name = US"oracle",                  /* lookup name */
+  .type = lookup_querystyle,           /* query-style lookup */
+  .open = oracle_open,                 /* open function */
+  .check = NULL,                       /* check function */
+  .find = oracle_find,                 /* find function */
+  .close = NULL,                       /* no close function */
+  .tidy = oracle_tidy,                 /* tidy function */
+  .quote = oracle_quote,               /* quoting function */
+  .version_report = oracle_version_report          /* version reporting */
 };
 
 #ifdef DYNLOOKUP