132 #include <postgres.h> 134 #include "utils/guc.h" 135 #include "utils/memutils.h" 137 #include "../../postgis_config.h" 138 #include "lwgeom_pg.h" 144 # define __attribute__ (x) 158 #define RT_MSG_MAXLEN 256 172 result = palloc(size);
185 result = repalloc(mem, size);
188 result = palloc(size);
211 ereport(ERROR, (errmsg_internal(
"%s", errmsg)));
225 ereport(NOTICE, (errmsg_internal(
"%s", msg)));
239 ereport(DEBUG1, (errmsg_internal(
"%s", msg)));
272 CPLSetConfigOption(
"GDAL_DATA", newpath);
282 char **enabled_drivers_array = NULL;
283 int enabled_drivers_count = 0;
284 bool *enabled_drivers_found = NULL;
285 char *gdal_skip = NULL;
294 if (enabled_drivers == NULL)
299 GDALDestroyDriverManager();
300 CPLSetConfigOption(
"GDAL_SKIP", NULL);
305 enabled_drivers_array =
rtpg_strsplit(enabled_drivers,
" ", &enabled_drivers_count);
306 enabled_drivers_found = palloc(
sizeof(
bool) * enabled_drivers_count);
307 memset(enabled_drivers_found,
FALSE,
sizeof(
bool) * enabled_drivers_count);
313 for (i = 0; i < enabled_drivers_count; i++) {
315 enabled_drivers_found[i] =
TRUE;
321 for (i = 0; i < enabled_drivers_count; i++) {
323 enabled_drivers_found[i] =
TRUE;
337 for (i = 0; i < drv_count; i++) {
342 if (strstr(enabled_drivers, drv_set[i].short_name) != NULL) {
344 for (j = 0; j < enabled_drivers_count; j++) {
346 if (strcmp(enabled_drivers_array[j], drv_set[i].short_name) == 0) {
347 enabled_drivers_found[j] =
TRUE;
359 if (gdal_skip == NULL) {
360 gdal_skip = palloc(
sizeof(
char) * (strlen(drv_set[i].short_name) + 1));
364 gdal_skip = repalloc(
367 strlen(gdal_skip) + 1 + strlen(drv_set[i].short_name) + 1
370 strcat(gdal_skip,
" ");
372 strcat(gdal_skip, drv_set[i].short_name);
375 for (i = 0; i < drv_count; i++) {
376 pfree(drv_set[i].short_name);
377 pfree(drv_set[i].long_name);
378 pfree(drv_set[i].create_options);
380 if (drv_count) pfree(drv_set);
384 for (i = 0; i < enabled_drivers_count; i++) {
385 if (enabled_drivers_found[i])
389 elog(WARNING,
"%s set. Ignoring GDAL driver: %s",
GDAL_DISABLE_ALL, enabled_drivers_array[i]);
391 elog(WARNING,
"%s set. Ignoring GDAL driver: %s",
GDAL_ENABLE_ALL, enabled_drivers_array[i]);
393 elog(WARNING,
"Unknown GDAL driver: %s", enabled_drivers_array[i]);
398 GDALDestroyDriverManager();
402 CPLSetConfigOption(
"GDAL_SKIP", gdal_skip);
403 if (gdal_skip != NULL) pfree(gdal_skip);
408 pfree(enabled_drivers_array);
409 pfree(enabled_drivers_found);
423 bool boot_postgis_enable_outdb_rasters =
false;
424 MemoryContext old_context;
430 old_context = MemoryContextSwitchTo(TopMemoryContext);
450 "boot_postgis_gdal_enabled_drivers = %s",
464 elog(ERROR,
"_PG_init: Cannot process environmental variable: POSTGIS_ENABLE_OUTDB_RASTERS");
468 if (strcmp(env,
"1") == 0)
469 boot_postgis_enable_outdb_rasters =
true;
476 "boot_postgis_enable_outdb_rasters = %s",
477 boot_postgis_enable_outdb_rasters ?
"TRUE" :
"FALSE" 481 pg_install_lwgeom_handlers();
487 if ( postgis_guc_find_option(
"postgis.gdal_datapath") )
492 elog(WARNING,
"'%s' is already set and cannot be changed until you reconnect",
"postgis.gdal_datapath");
496 DefineCustomStringVariable(
497 "postgis.gdal_datapath",
498 "Path to GDAL data files.",
499 "Physical path to directory containing GDAL data files (sets the GDAL_DATA config option).",
510 if ( postgis_guc_find_option(
"postgis.gdal_enabled_drivers") )
515 elog(WARNING,
"'%s' is already set and cannot be changed until you reconnect",
"postgis.gdal_enabled_drivers");
519 DefineCustomStringVariable(
520 "postgis.gdal_enabled_drivers",
521 "Enabled GDAL drivers.",
522 "List of enabled GDAL drivers by short name. To enable/disable all drivers, use 'ENABLE_ALL' or 'DISABLE_ALL' (sets the GDAL_SKIP config option).",
533 if ( postgis_guc_find_option(
"postgis.enable_outdb_rasters") )
538 elog(WARNING,
"'%s' is already set and cannot be changed until you reconnect",
"postgis.enable_outdb_rasters");
542 DefineCustomBoolVariable(
543 "postgis.enable_outdb_rasters",
544 "Enable Out-DB raster bands",
545 "If true, rasters can access data located outside the database",
547 boot_postgis_enable_outdb_rasters,
557 MemoryContextSwitchTo(old_context);
564 MemoryContext old_context;
566 old_context = MemoryContextSwitchTo(TopMemoryContext);
578 MemoryContextSwitchTo(old_context);
char ** rtpg_strsplit(const char *str, const char *delimiter, int *n)
int rt_util_gdal_register_all(int force_register_all)
static void rtpg_assignHookGDALEnabledDrivers(const char *enabled_drivers, void *extra)
void rt_set_handlers(rt_allocator allocator, rt_reallocator reallocator, rt_deallocator deallocator, rt_message_handler error_handler, rt_message_handler info_handler, rt_message_handler warning_handler)
This function is called when the PostgreSQL backend is taking care of the memory and we want to use p...
static void rt_pg_notice(const char *fmt, va_list ap) __attribute__((format(printf
static char * env_postgis_gdal_enabled_drivers
static char * env_postgis_enable_outdb_rasters
#define POSTGIS_RT_DEBUGF(level, msg,...)
static void rtpg_assignHookEnableOutDBRasters(bool enable, void *extra)
char * gdal_enabled_drivers
static char * boot_postgis_gdal_enabled_drivers
bool enable_outdb_rasters
static char * gdal_datapath
char * rtpg_trim(const char *input)
static void rt_pg_error(const char *fmt, va_list ap) __attribute__((format(printf
static void rt_pg_free(void *ptr)
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
static void rt_pg_debug(const char *fmt, va_list ap) __attribute__((format(printf
static void * rt_pg_alloc(size_t size)
#define POSTGIS_RT_DEBUG(level, msg)
static void rtpg_assignHookGDALDataPath(const char *newpath, void *extra)
static void * rt_pg_realloc(void *mem, size_t size)