PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ rtpg_assignHookGDALEnabledDrivers()

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

Definition at line 485 of file rtpostgis.c.

485  {
486  int enable_all = 0;
487  int disable_all = 0;
488  int vsicurl = 0;
489 
490  char **enabled_drivers_array = NULL;
491  uint32_t enabled_drivers_count = 0;
492  bool *enabled_drivers_found = NULL;
493  char *gdal_skip = NULL;
494 
495  uint32_t i;
496  uint32_t j;
497 
498  POSTGIS_RT_DEBUGF(4, "GDAL_SKIP = %s", CPLGetConfigOption("GDAL_SKIP", ""));
499  POSTGIS_RT_DEBUGF(4, "enabled_drivers = %s", enabled_drivers);
500 
501  /* if NULL, nothing to do */
502  if (enabled_drivers == NULL)
503  return;
504 
505  elog(DEBUG4, "Enabling GDAL drivers: %s", enabled_drivers);
506 
507  /* destroy the driver manager */
508  /* this is the only way to ensure GDAL_SKIP is recognized */
509  GDALDestroyDriverManager();
510  CPLSetConfigOption("GDAL_SKIP", NULL);
511 
512  /* force wrapper function to call GDALAllRegister() */
514 
515  enabled_drivers_array = rtpg_strsplit(enabled_drivers, " ", &enabled_drivers_count);
516  enabled_drivers_found = palloc(sizeof(bool) * enabled_drivers_count);
517  memset(enabled_drivers_found, FALSE, sizeof(bool) * enabled_drivers_count);
518 
519  /* scan for keywords DISABLE_ALL and ENABLE_ALL */
520  disable_all = 0;
521  enable_all = 0;
522  if (strstr(enabled_drivers, GDAL_DISABLE_ALL) != NULL) {
523  for (i = 0; i < enabled_drivers_count; i++) {
524  if (strstr(enabled_drivers_array[i], GDAL_DISABLE_ALL) != NULL) {
525  enabled_drivers_found[i] = TRUE;
526  disable_all = 1;
527  }
528  }
529  }
530  else if (strstr(enabled_drivers, GDAL_ENABLE_ALL) != NULL) {
531  for (i = 0; i < enabled_drivers_count; i++) {
532  if (strstr(enabled_drivers_array[i], GDAL_ENABLE_ALL) != NULL) {
533  enabled_drivers_found[i] = TRUE;
534  enable_all = 1;
535  }
536  }
537  }
538  else if (strstr(enabled_drivers, GDAL_VSICURL) != NULL) {
539  for (i = 0; i < enabled_drivers_count; i++) {
540  if (strstr(enabled_drivers_array[i], GDAL_VSICURL) != NULL) {
541  enabled_drivers_found[i] = TRUE;
542  vsicurl = 1;
543  }
544  }
545  }
546 
547  if (!enable_all) {
548  int found = 0;
549  uint32_t drv_count = 0;
550  rt_gdaldriver drv_set = rt_raster_gdal_drivers(&drv_count, 0);
551 
552  POSTGIS_RT_DEBUGF(4, "driver count = %d", drv_count);
553 
554  /* all other drivers than those in new drivers are added to GDAL_SKIP */
555  for (i = 0; i < drv_count; i++) {
556  found = 0;
557 
558  if (!disable_all) {
559  /* gdal driver found in enabled_drivers, continue to thorough search */
560  if (strstr(enabled_drivers, drv_set[i].short_name) != NULL) {
561  /* thorough search of enabled_drivers */
562  for (j = 0; j < enabled_drivers_count; j++) {
563  /* driver found */
564  if (strcmp(enabled_drivers_array[j], drv_set[i].short_name) == 0) {
565  enabled_drivers_found[j] = TRUE;
566  found = 1;
567  }
568  }
569  }
570  }
571 
572  /* driver found, continue */
573  if (found)
574  continue;
575 
576  /* driver not found, add to gdal_skip */
577  if (gdal_skip == NULL) {
578  gdal_skip = palloc(sizeof(char) * (strlen(drv_set[i].short_name) + 1));
579  gdal_skip[0] = '\0';
580  }
581  else {
582  gdal_skip = repalloc(
583  gdal_skip,
584  sizeof(char) * (
585  strlen(gdal_skip) + 1 + strlen(drv_set[i].short_name) + 1
586  )
587  );
588  strcat(gdal_skip, " ");
589  }
590  strcat(gdal_skip, drv_set[i].short_name);
591  }
592 
593  for (i = 0; i < drv_count; i++) {
594  pfree(drv_set[i].short_name);
595  pfree(drv_set[i].long_name);
596  pfree(drv_set[i].create_options);
597  }
598  if (drv_count) pfree(drv_set);
599 
600  }
601 
602  for (i = 0; i < enabled_drivers_count; i++) {
603  if (enabled_drivers_found[i])
604  continue;
605 
606  if (disable_all)
607  elog(WARNING, "%s set. Ignoring GDAL driver: %s", GDAL_DISABLE_ALL, enabled_drivers_array[i]);
608  else if (enable_all)
609  elog(WARNING, "%s set. Ignoring GDAL driver: %s", GDAL_ENABLE_ALL, enabled_drivers_array[i]);
610  else
611  elog(WARNING, "Unknown GDAL driver: %s", enabled_drivers_array[i]);
612  }
613 
614  if (vsicurl)
615  elog(WARNING, "%s set.", GDAL_VSICURL);
616 
617  /* destroy the driver manager */
618  /* this is the only way to ensure GDAL_SKIP is recognized */
619  GDALDestroyDriverManager();
620 
621  /* set GDAL_SKIP */
622  POSTGIS_RT_DEBUGF(4, "gdal_skip = %s", gdal_skip);
623  CPLSetConfigOption("GDAL_SKIP", gdal_skip);
624  if (gdal_skip != NULL) pfree(gdal_skip);
625 
626  /* force wrapper function to call GDALAllRegister() */
628 
629  pfree(enabled_drivers_array);
630  pfree(enabled_drivers_found);
631  POSTGIS_RT_DEBUGF(4, "GDAL_SKIP = %s", CPLGetConfigOption("GDAL_SKIP", ""));
632 }
#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:339
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
Definition: rt_raster.c:1838
#define GDAL_ENABLE_ALL
Definition: librtcore.h:2192
#define GDAL_DISABLE_ALL
Definition: librtcore.h:2193
#define GDAL_VSICURL
Definition: librtcore.h:2194
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: