Skip to content

Commit bc9d4a0

Browse files
committed
Set environment variables in config file and send to cURL
1 parent 47d2757 commit bc9d4a0

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;
@@ -1265,6 +1275,11 @@ void mapcache_configuration_parse_xml(mapcache_context *ctx, const char *filenam
12651275
if(GC_HAS_ERROR(ctx)) goto cleanup;
12661276
}
12671277

1278+
for (node = ezxml_child(doc, "environment"); node; node = node->next) {
1279+
parseEnvironment(ctx, node);
1280+
if (GC_HAS_ERROR(ctx)) goto cleanup;
1281+
}
1282+
12681283
for(node = ezxml_child(doc,"source"); node; node = node->next) {
12691284
parseSource(ctx, node, config);
12701285
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>
@@ -361,7 +372,7 @@
361372
Similar to symlink_blank, except completely skip writing a file
362373
if a blank, fully transparent tile is detected.
363374
Note: This setting should only be used when using the seeder. If used
364-
on demand, mapcache will will query the WMS source on each subsequent
375+
on demand, mapcache will query the WMS source on each subsequent
365376
tile request.
366377
-->
367378
<detect_blank/>
@@ -385,7 +396,7 @@
385396
* note that this type of cache does not support blank-tile detection and symlinking.
386397
387398
* warning: it is up to you to make sure that the template you chose creates a unique
388-
filename for your given tilesets. e.g. do not ommit the {grid} parameter if your
399+
filename for your given tilesets. e.g. do not omit the {grid} parameter if your
389400
tilesets reference multiple grids. Failure to do so will result in filename
390401
collisions !
391402
@@ -396,7 +407,7 @@
396407
Similar to symlink_blank, except completely skip writing a file
397408
if a blank, fully transparent tile is detected.
398409
Note: This setting should only be used when using the seeder. If used
399-
on demand, mapcache will will query the WMS source on each subsequent
410+
on demand, mapcache will query the WMS source on each subsequent
400411
tile request.
401412
-->
402413
<detect_blank/>
@@ -426,10 +437,10 @@
426437
<dbfile>/tmp/mysqlitetiles.db</dbfile>
427438

428439
<!-- pragma
429-
special sqlite pargmas sent to db at connection time. The following
440+
special sqlite pragmas sent to db at connection time. The following
430441
would execute:
431442
PRAGMA key=value;
432-
usefull for changing default values e.g. on large databases.
443+
useful for changing default values e.g. on large databases.
433444
434445
-->
435446
<pragma name="key">value</pragma>
@@ -577,7 +588,7 @@
577588
578589
png compression: best or fast
579590
note that "best" compression is cpu intensive for little gain over the default
580-
default compression is obtained by leving out this tag.
591+
default compression is obtained by leaving out this tag.
581592
-->
582593
<compression>fast</compression>
583594

@@ -681,7 +692,7 @@
681692
<connection_timeout>30</connection_timeout>
682693

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

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

0 commit comments

Comments
 (0)