PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ rtpg_assignHookGDALEnabledDrivers()

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

Definition at line 493 of file rtpostgis.c.

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

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: