PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ rtpg_assignHookGDALEnabledDrivers()

static void rtpg_assignHookGDALEnabledDrivers ( const char *  enabled_drivers,
void *  extra 
)
static

Definition at line 278 of file rtpostgis.c.

278  {
279  int enable_all = 0;
280  int disable_all = 0;
281  int vsicurl = 0;
282 
283  char **enabled_drivers_array = NULL;
284  uint32_t enabled_drivers_count = 0;
285  bool *enabled_drivers_found = NULL;
286  char *gdal_skip = NULL;
287 
288  uint32_t i;
289  uint32_t j;
290 
291  POSTGIS_RT_DEBUGF(4, "GDAL_SKIP = %s", CPLGetConfigOption("GDAL_SKIP", ""));
292  POSTGIS_RT_DEBUGF(4, "enabled_drivers = %s", enabled_drivers);
293 
294  /* if NULL, nothing to do */
295  if (enabled_drivers == NULL)
296  return;
297 
298  elog(DEBUG4, "Enabling GDAL drivers: %s", enabled_drivers);
299 
300  /* destroy the driver manager */
301  /* this is the only way to ensure GDAL_SKIP is recognized */
302  GDALDestroyDriverManager();
303  CPLSetConfigOption("GDAL_SKIP", NULL);
304 
305  /* force wrapper function to call GDALAllRegister() */
307 
308  enabled_drivers_array = rtpg_strsplit(enabled_drivers, " ", &enabled_drivers_count);
309  enabled_drivers_found = palloc(sizeof(bool) * enabled_drivers_count);
310  memset(enabled_drivers_found, FALSE, sizeof(bool) * enabled_drivers_count);
311 
312  /* scan for keywords DISABLE_ALL and ENABLE_ALL */
313  disable_all = 0;
314  enable_all = 0;
315  if (strstr(enabled_drivers, GDAL_DISABLE_ALL) != NULL) {
316  for (i = 0; i < enabled_drivers_count; i++) {
317  if (strstr(enabled_drivers_array[i], GDAL_DISABLE_ALL) != NULL) {
318  enabled_drivers_found[i] = TRUE;
319  disable_all = 1;
320  }
321  }
322  }
323  else if (strstr(enabled_drivers, GDAL_ENABLE_ALL) != NULL) {
324  for (i = 0; i < enabled_drivers_count; i++) {
325  if (strstr(enabled_drivers_array[i], GDAL_ENABLE_ALL) != NULL) {
326  enabled_drivers_found[i] = TRUE;
327  enable_all = 1;
328  }
329  }
330  }
331  else if (strstr(enabled_drivers, GDAL_VSICURL) != NULL) {
332  for (i = 0; i < enabled_drivers_count; i++) {
333  if (strstr(enabled_drivers_array[i], GDAL_VSICURL) != NULL) {
334  enabled_drivers_found[i] = TRUE;
335  vsicurl = 1;
336  }
337  }
338  }
339 
340  if (!enable_all) {
341  int found = 0;
342  uint32_t drv_count = 0;
343  rt_gdaldriver drv_set = rt_raster_gdal_drivers(&drv_count, 0);
344 
345  POSTGIS_RT_DEBUGF(4, "driver count = %d", drv_count);
346 
347  /* all other drivers than those in new drivers are added to GDAL_SKIP */
348  for (i = 0; i < drv_count; i++) {
349  found = 0;
350 
351  if (!disable_all) {
352  /* gdal driver found in enabled_drivers, continue to thorough search */
353  if (strstr(enabled_drivers, drv_set[i].short_name) != NULL) {
354  /* thorough search of enabled_drivers */
355  for (j = 0; j < enabled_drivers_count; j++) {
356  /* driver found */
357  if (strcmp(enabled_drivers_array[j], drv_set[i].short_name) == 0) {
358  enabled_drivers_found[j] = TRUE;
359  found = 1;
360  }
361  }
362  }
363  }
364 
365  /* driver found, continue */
366  if (found)
367  continue;
368 
369  /* driver not found, add to gdal_skip */
370  if (gdal_skip == NULL) {
371  gdal_skip = palloc(sizeof(char) * (strlen(drv_set[i].short_name) + 1));
372  gdal_skip[0] = '\0';
373  }
374  else {
375  gdal_skip = repalloc(
376  gdal_skip,
377  sizeof(char) * (
378  strlen(gdal_skip) + 1 + strlen(drv_set[i].short_name) + 1
379  )
380  );
381  strcat(gdal_skip, " ");
382  }
383  strcat(gdal_skip, drv_set[i].short_name);
384  }
385 
386  for (i = 0; i < drv_count; i++) {
387  pfree(drv_set[i].short_name);
388  pfree(drv_set[i].long_name);
389  pfree(drv_set[i].create_options);
390  }
391  if (drv_count) pfree(drv_set);
392 
393  }
394 
395  for (i = 0; i < enabled_drivers_count; i++) {
396  if (enabled_drivers_found[i])
397  continue;
398 
399  if (disable_all)
400  elog(WARNING, "%s set. Ignoring GDAL driver: %s", GDAL_DISABLE_ALL, enabled_drivers_array[i]);
401  else if (enable_all)
402  elog(WARNING, "%s set. Ignoring GDAL driver: %s", GDAL_ENABLE_ALL, enabled_drivers_array[i]);
403  else
404  elog(WARNING, "Unknown GDAL driver: %s", enabled_drivers_array[i]);
405  }
406 
407  if (vsicurl)
408  elog(WARNING, "%s set.", GDAL_VSICURL);
409 
410  /* destroy the driver manager */
411  /* this is the only way to ensure GDAL_SKIP is recognized */
412  GDALDestroyDriverManager();
413 
414  /* set GDAL_SKIP */
415  POSTGIS_RT_DEBUGF(4, "gdal_skip = %s", gdal_skip);
416  CPLSetConfigOption("GDAL_SKIP", gdal_skip);
417  if (gdal_skip != NULL) pfree(gdal_skip);
418 
419  /* force wrapper function to call GDALAllRegister() */
421 
422  pfree(enabled_drivers_array);
423  pfree(enabled_drivers_found);
424  POSTGIS_RT_DEBUGF(4, "GDAL_SKIP = %s", CPLGetConfigOption("GDAL_SKIP", ""));
425 }
#define TRUE
Definition: dbfopen.c:73
#define FALSE
Definition: dbfopen.c:72
int rt_util_gdal_register_all(int force_register_all)
Definition: rt_util.c:338
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
Definition: rt_raster.c:1711
#define GDAL_ENABLE_ALL
Definition: librtcore.h:2048
#define GDAL_DISABLE_ALL
Definition: librtcore.h:2049
#define GDAL_VSICURL
Definition: librtcore.h:2050
char ** rtpg_strsplit(const char *str, const char *delimiter, uint32_t *n)
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:65

References FALSE, GDAL_DISABLE_ALL, GDAL_ENABLE_ALL, GDAL_VSICURL, POSTGIS_RT_DEBUGF, rt_raster_gdal_drivers(), rt_util_gdal_register_all(), rtpg_strsplit(), and TRUE.

Referenced by _PG_init().

Here is the call graph for this function:
Here is the caller graph for this function: