Skip to content

Commit 7bc0ad9

Browse files
authored
Merge pull request #261 from geographika/set-environ-variables
Allow environment variables to be set in config file
2 parents ee833ac + bc9d4a0 commit 7bc0ad9

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

lib/configuration_xml.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ void parseMetadata(mapcache_context *ctx, ezxml_t node, apr_table_t *metadata)
6060
}
6161
}
6262

63+
void parseEnvironment(mapcache_context* ctx, ezxml_t node)
64+
{
65+
ezxml_t cur_node;
66+
for (cur_node = node->child; cur_node; cur_node = cur_node->ordered) {
67+
if (!cur_node->child) {
68+
putenv(apr_psprintf(ctx->pool, "%s=%s", cur_node->name, cur_node->txt));
69+
}
70+
}
71+
}
72+
6373
void parseDimensions(mapcache_context *ctx, ezxml_t node, mapcache_tileset *tileset)
6474
{
6575
ezxml_t dimension_node;
@@ -1267,6 +1277,11 @@ void mapcache_configuration_parse_xml(mapcache_context *ctx, const char *filenam
12671277
if(GC_HAS_ERROR(ctx)) goto cleanup;
12681278
}
12691279

1280+
for (node = ezxml_child(doc, "environment"); node; node = node->next) {
1281+
parseEnvironment(ctx, node);
1282+
if (GC_HAS_ERROR(ctx)) goto cleanup;
1283+
}
1284+
12701285
for(node = ezxml_child(doc,"source"); node; node = node->next) {
12711286
parseSource(ctx, node, config);
12721287
if(GC_HAS_ERROR(ctx)) goto cleanup;

lib/http.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,16 @@ void mapcache_http_do_request(mapcache_context *ctx, mapcache_http *req, mapcach
104104
CURL *curl_handle;
105105
char error_msg[CURL_ERROR_SIZE];
106106
int ret;
107+
const char* ca_bundle = NULL;
107108
struct curl_slist *curl_headers=NULL;
108109
struct _header_struct h;
109110
curl_handle = curl_easy_init();
110111

112+
ca_bundle = getenv("CURL_CA_BUNDLE");
113+
114+
if (ca_bundle) {
115+
curl_easy_setopt(curl_handle, CURLOPT_CAINFO, ca_bundle);
116+
}
111117

112118
/* specify URL to get */
113119
curl_easy_setopt(curl_handle, CURLOPT_URL, req->url);
@@ -135,7 +141,6 @@ void mapcache_http_do_request(mapcache_context *ctx, mapcache_http *req, mapcach
135141
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
136142

137143

138-
139144
if(req->headers) {
140145
const apr_array_header_t *array = apr_table_elts(req->headers);
141146
apr_table_entry_t *elts = (apr_table_entry_t *) array->elts;

mapcache.xml.sample

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
-->
1616
</metadata>
1717

18+
<environment>
19+
20+
<!--
21+
22+
environment variables can be set and overridden here
23+
this is useful on Windows servers to set a path
24+
to a certificates file when connecting to sources using HTTPS
25+
26+
<CURL_CA_BUNDLE>C:/MapServer/bin/curl-ca-bundle.crt</CURL_CA_BUNDLE>
27+
-->
28+
</environment>
1829
<!--
1930
a grid represents the layout of tiles: srs, extent, resolutions, and tile size
2031
-->
@@ -30,7 +41,7 @@
3041
<!--
3142
Set to "true" if no new tiles should be created when not in
3243
the configured cache. If a requested tile is not present in
33-
a read-only cache, it wil be returned as "nodata", i.e. fully
44+
a read-only cache, it will be returned as "nodata", i.e. fully
3445
transparent in a vertical assembly case, or as a 404 in a
3546
single-tile case.
3647
Note that the read-only status of a tileset is overridden to
@@ -84,7 +95,7 @@
8495

8596
<!--
8697
there are three preconfigured grids you can use in <tileset>s without having to
87-
explicitely define them here:
98+
explicitly define them here:
8899
<grid name="WGS84">
89100
<metadata>
90101
<title>GoogleCRS84Quad</title>
@@ -364,7 +375,7 @@
364375
Similar to symlink_blank, except completely skip writing a file
365376
if a blank, fully transparent tile is detected.
366377
Note: This setting should only be used when using the seeder. If used
367-
on demand, mapcache will will query the WMS source on each subsequent
378+
on demand, mapcache will query the WMS source on each subsequent
368379
tile request.
369380
-->
370381
<detect_blank/>
@@ -388,7 +399,7 @@
388399
* note that this type of cache does not support blank-tile detection and symlinking.
389400
390401
* warning: it is up to you to make sure that the template you chose creates a unique
391-
filename for your given tilesets. e.g. do not ommit the {grid} parameter if your
402+
filename for your given tilesets. e.g. do not omit the {grid} parameter if your
392403
tilesets reference multiple grids. Failure to do so will result in filename
393404
collisions !
394405
@@ -399,7 +410,7 @@
399410
Similar to symlink_blank, except completely skip writing a file
400411
if a blank, fully transparent tile is detected.
401412
Note: This setting should only be used when using the seeder. If used
402-
on demand, mapcache will will query the WMS source on each subsequent
413+
on demand, mapcache will query the WMS source on each subsequent
403414
tile request.
404415
-->
405416
<detect_blank/>
@@ -437,10 +448,10 @@
437448
<dbfile>/tmp/mysqlitetiles.db</dbfile>
438449

439450
<!-- pragma
440-
special sqlite pargmas sent to db at connection time. The following
451+
special sqlite pragmas sent to db at connection time. The following
441452
would execute:
442453
PRAGMA key=value;
443-
usefull for changing default values e.g. on large databases.
454+
useful for changing default values e.g. on large databases.
444455
445456
-->
446457
<pragma name="key">value</pragma>
@@ -588,7 +599,7 @@
588599
589600
png compression: best or fast
590601
note that "best" compression is cpu intensive for little gain over the default
591-
default compression is obtained by leving out this tag.
602+
default compression is obtained by leaving out this tag.
592603
-->
593604
<compression>fast</compression>
594605

@@ -692,7 +703,7 @@
692703
<connection_timeout>30</connection_timeout>
693704

694705
<!-- timeout in seconds before bailing out from a request. This is the total time needed
695-
to fullfill the request, and includes the time needed to transfer the response through
706+
to fulfill the request, and includes the time needed to transfer the response through
696707
the network. Defaults to 600 seconds, set to a higher value if e.g. WMS requests for
697708
large metatiles take longer than 10 minutes to render -->
698709
<timeout>300</timeout>
@@ -809,7 +820,7 @@
809820

810821
<!-- format
811822
(optional) format to use when storing a tile. this should be a format with high
812-
compression, eg. png with compression "best", as the compression operation is only
823+
compression, e.g. png with compression "best", as the compression operation is only
813824
done once at creation time.
814825
if left out, no recompression is applied to the image, mod-mapcache will store the
815826
exact image received from the <source>
@@ -879,8 +890,8 @@
879890
mapserver mapfiles. the name of the mapfiles need not be known to mod-mapcache, and can therefore be
880891
created even after mod-mapcache has been started.
881892
when a user passes a MAPFILE=/path/to/mapfile, the string "/path/to/mapfile" is validated against
882-
the supplied (PCRE) regular expression. The one in this example allows a name composed of aphanumeric characters
883-
spearated by slashes (/) and finishing with ".map" ( [a-zA-Z0-9\./]*\.map$ ) , but will faill if there
893+
the supplied (PCRE) regular expression. The one in this example allows a name composed of alphanumeric characters
894+
separated by slashes (/) and finishing with ".map" ( [a-zA-Z0-9\./]*\.map$ ) , but will fail if there
884895
are two consecutive dots (..) in the path, to prevent filesystem traversal ( (?!.*\.\.) ).
885896
-->
886897
<dimension type="regex" name="MAPFILE" default="/path/to/mapfile.map">

0 commit comments

Comments
 (0)