PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void rtpg_assignHookGDALEnabledDrivers ( )
static

Definition at line 172 of file rt_pg.c.

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

Referenced by _PG_init().

172  {
173  char *enabled_drivers = NULL;
174  int enable_all = 0;
175  int disable_all = 0;
176 
177  char **enabled_drivers_array = NULL;
178  int enabled_drivers_count = 0;
179  bool *enabled_drivers_found = NULL;
180  char *gdal_skip = NULL;
181 
182  uint32_t i;
183  uint32_t j;
184 
185  enabled_drivers = getenv(ENV_POSTGIS_GDAL_ENABLED_DRIVERS);
186 
187  POSTGIS_RT_DEBUGF(4, "GDAL_SKIP = \"%s\"", CPLGetConfigOption("GDAL_SKIP", ""));
188  POSTGIS_RT_DEBUGF(4, "enabled_drivers = \"%s\"", enabled_drivers);
189 
190  if (enabled_drivers != NULL) {
191  gdal_enabled_drivers = palloc(
192  sizeof(char) * (strlen(enabled_drivers) + 1)
193  );
194 
195  sprintf(gdal_enabled_drivers, "%s", enabled_drivers);
196 
197  enabled_drivers_array = rtpg_strsplit(enabled_drivers, " ", &enabled_drivers_count);
198 #if POSTGIS_DEBUG_LEVEL > 0
199  POSTGIS_RT_DEBUGF(4, "enabled_drivers_count = %d", enabled_drivers_count)
200  for (i = 0; i < enabled_drivers_count; i++) {
201  POSTGIS_RT_DEBUGF(4, "enabled_drivers_array[%d] = \"%s\"", i, enabled_drivers_array[i]);
202  }
203 #endif
204 
205  enabled_drivers_found = palloc(sizeof(bool) * enabled_drivers_count);
206  memset(enabled_drivers_found, FALSE, sizeof(bool) * enabled_drivers_count);
207  }
208  else {
209  gdal_enabled_drivers = palloc(sizeof(char));
210  gdal_enabled_drivers[0] = '\0';
211  }
212 
213  /* destroy the driver manager */
214  /* this is the only way to ensure GDAL_SKIP is recognized */
215  GDALDestroyDriverManager();
216  CPLSetConfigOption("GDAL_SKIP", NULL);
217 
218  /* force wrapper function to call GDALAllRegister() */
220 
221  /* scan for keywords DISABLE_ALL and ENABLE_ALL */
222  disable_all = 0;
223  enable_all = 0;
224  if (strstr(gdal_enabled_drivers, GDAL_DISABLE_ALL) != NULL) {
225  for (i = 0; i < enabled_drivers_count; i++) {
226  if (strstr(enabled_drivers_array[i], GDAL_DISABLE_ALL) != NULL) {
227  enabled_drivers_found[i] = TRUE;
228  disable_all = 1;
229  }
230  }
231  }
232  else if (strstr(gdal_enabled_drivers, GDAL_ENABLE_ALL) != NULL) {
233  for (i = 0; i < enabled_drivers_count; i++) {
234  if (strstr(enabled_drivers_array[i], GDAL_ENABLE_ALL) != NULL) {
235  enabled_drivers_found[i] = TRUE;
236  enable_all = 1;
237  }
238  }
239  }
240 
241  if (!enable_all) {
242  int found = 0;
243  uint32_t drv_count = 0;
244  rt_gdaldriver drv_set = rt_raster_gdal_drivers(&drv_count, 0);
245 
246  POSTGIS_RT_DEBUGF(4, "driver count = %d", drv_count);
247 
248  /* all other drivers than those in new drivers are added to GDAL_SKIP */
249  for (i = 0; i < drv_count; i++) {
250  POSTGIS_RT_DEBUGF(4, "drv_set[%d] = \"%s\"", i, drv_set[i].short_name);
251  found = 0;
252 
253  if (!disable_all) {
254  /* gdal driver found in gdal_enabled_drivers, continue to thorough search */
255  if (strstr(gdal_enabled_drivers, drv_set[i].short_name) != NULL) {
256  POSTGIS_RT_DEBUGF(4, "\"%s\" found in gdal_enabled_drivers", drv_set[i].short_name);
257  /* thorough search of enabled_drivers */
258  for (j = 0; j < enabled_drivers_count; j++) {
259  /* driver found */
260  if (strcmp(enabled_drivers_array[j], drv_set[i].short_name) == 0) {
261  POSTGIS_RT_DEBUGF(4, "\"%s\" found in enabled_drivers_array", drv_set[i].short_name);
262  enabled_drivers_found[j] = TRUE;
263  found = 1;
264  }
265  }
266  }
267  }
268 
269  /* driver found, continue */
270  if (found)
271  continue;
272 
273  /* driver not found, add to gdal_skip */
274  if (gdal_skip == NULL) {
275  gdal_skip = palloc(sizeof(char) * (strlen(drv_set[i].short_name) + 1));
276  gdal_skip[0] = '\0';
277  }
278  else {
279  gdal_skip = repalloc(
280  gdal_skip,
281  sizeof(char) * (
282  strlen(gdal_skip) + 1 + strlen(drv_set[i].short_name) + 1
283  )
284  );
285  strcat(gdal_skip, " ");
286  }
287  strcat(gdal_skip, drv_set[i].short_name);
288  }
289 
290  for (i = 0; i < drv_count; i++) {
291  pfree(drv_set[i].short_name);
292  pfree(drv_set[i].long_name);
293  pfree(drv_set[i].create_options);
294  }
295  if (drv_count) pfree(drv_set);
296 
297  }
298 
299  for (i = 0; i < enabled_drivers_count; i++) {
300  if (enabled_drivers_found[i])
301  continue;
302 
303  if (disable_all)
304  elog(WARNING, "%s set. Ignoring GDAL driver: %s", GDAL_DISABLE_ALL, enabled_drivers_array[i]);
305  else if (enable_all)
306  elog(WARNING, "%s set. Ignoring GDAL driver: %s", GDAL_ENABLE_ALL, enabled_drivers_array[i]);
307  else
308  elog(WARNING, "Unknown GDAL driver: %s", enabled_drivers_array[i]);
309  }
310 
311  /* destroy the driver manager */
312  /* this is the only way to ensure GDAL_SKIP is recognized */
313  GDALDestroyDriverManager();
314 
315  /* set GDAL_SKIP */
316  POSTGIS_RT_DEBUGF(4, "gdal_skip = \"%s\"", gdal_skip);
317  CPLSetConfigOption("GDAL_SKIP", gdal_skip);
318  if (gdal_skip != NULL) pfree(gdal_skip);
319 
320  /* force wrapper function to call GDALAllRegister() */
322 
323  if (enabled_drivers_count) {
324  pfree(enabled_drivers_array);
325  pfree(enabled_drivers_found);
326  }
327  POSTGIS_RT_DEBUGF(4, "GDAL_SKIP = \"%s\"", CPLGetConfigOption("GDAL_SKIP", ""));
328 }
int rt_util_gdal_register_all(int force_register_all)
Definition: rt_api.c:445
#define ENV_POSTGIS_GDAL_ENABLED_DRIVERS
Definition: rt_pg.c:95
#define GDAL_ENABLE_ALL
Definition: rt_api.h:1975
static char ** rtpg_strsplit(const char *str, const char *delimiter, int *n)
Definition: rt_pg.c:772
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
Definition: rt_api.c:8891
#define FALSE
Definition: dbfopen.c:169
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rt_pg.h:62
char * gdal_enabled_drivers
Definition: rt_api.c:481
#define GDAL_DISABLE_ALL
Definition: rt_api.h:1976
#define TRUE
Definition: dbfopen.c:170

Here is the call graph for this function:

Here is the caller graph for this function: