PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ rtpg_assignHookGDALEnabledDrivers()

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

Definition at line 278 of file rtpostgis.c.

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

Referenced by _PG_init().

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