PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ rtpg_assignHookGDALEnabledDrivers()

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

Definition at line 486 of file rtpostgis.c.

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

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: