/
mapcache.h
1672 lines (1353 loc) · 53.8 KB
/
mapcache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
*
* Project: MapCache
* Author: Thomas Bonfort and the MapServer team.
*
******************************************************************************
* Copyright (c) 1996-2011 Regents of the University of Minnesota.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies of this Software or works derived from this Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
/*! \file mapcache.h
\brief global function and structure declarations
*/
#ifndef MAPCACHE_H_
#define MAPCACHE_H_
#include "mapcache-config.h"
#include "mapcache-version.h"
#include <apr_tables.h>
#include <apr_hash.h>
#include <apr_reslist.h>
#include "util.h"
#include "ezxml.h"
#include "errors.h"
#include <assert.h>
#include <time.h>
#include <apr_time.h>
#define MAPCACHE_SUCCESS 0
#define MAPCACHE_FAILURE 1
#define MAPCACHE_TRUE 1
#define MAPCACHE_FALSE 0
#define MAPCACHE_TILESET_WRONG_SIZE 2
#define MAPCACHE_TILESET_WRONG_RESOLUTION 3
#define MAPCACHE_TILESET_WRONG_EXTENT 4
#define MAPCACHE_CACHE_MISS 5
#define MAPCACHE_FILE_LOCKED 6
#define MAPCACHE_CACHE_RELOAD 7
#define MAPCACHE_MAX_NUM_TILES 1000
#define MAPCACHE_USERAGENT "mod-mapcache/"MAPCACHE_VERSION
#if defined(_WIN32) && !defined(__CYGWIN__)
# define MS_DLL_EXPORT __declspec(dllexport)
#else
#define MS_DLL_EXPORT
#endif
typedef struct mapcache_image_format mapcache_image_format;
typedef struct mapcache_image_format_mixed mapcache_image_format_mixed;
typedef struct mapcache_image_format_png mapcache_image_format_png;
typedef struct mapcache_image_format_png_q mapcache_image_format_png_q;
typedef struct mapcache_image_format_jpeg mapcache_image_format_jpeg;
typedef struct mapcache_image_format_raw mapcache_image_format_raw;
typedef struct mapcache_cfg mapcache_cfg;
typedef struct mapcache_tileset mapcache_tileset;
typedef struct mapcache_cache mapcache_cache;
typedef struct mapcache_source mapcache_source;
typedef struct mapcache_buffer mapcache_buffer;
typedef struct mapcache_tile mapcache_tile;
typedef struct mapcache_metatile mapcache_metatile;
typedef struct mapcache_feature_info mapcache_feature_info;
typedef struct mapcache_request_get_feature_info mapcache_request_get_feature_info;
typedef struct mapcache_map mapcache_map;
typedef struct mapcache_http_response mapcache_http_response;
typedef struct mapcache_http mapcache_http;
typedef struct mapcache_request mapcache_request;
typedef struct mapcache_request_image mapcache_request_image;
typedef struct mapcache_request_proxy mapcache_request_proxy;
typedef struct mapcache_request_get_capabilities mapcache_request_get_capabilities;
typedef struct mapcache_forwarding_rule mapcache_forwarding_rule;
typedef struct mapcache_request_get_tile mapcache_request_get_tile;
typedef struct mapcache_request_get_map mapcache_request_get_map;
typedef struct mapcache_service mapcache_service;
typedef struct mapcache_server_cfg mapcache_server_cfg;
typedef struct mapcache_image mapcache_image;
typedef struct mapcache_grid mapcache_grid;
typedef struct mapcache_grid_level mapcache_grid_level;
typedef struct mapcache_grid_link mapcache_grid_link;
typedef struct mapcache_context mapcache_context;
typedef struct mapcache_dimension mapcache_dimension;
typedef struct mapcache_requested_dimension mapcache_requested_dimension;
typedef struct mapcache_extent mapcache_extent;
typedef struct mapcache_extent_i mapcache_extent_i;
typedef struct mapcache_connection_pool mapcache_connection_pool;
typedef struct mapcache_locker mapcache_locker;
typedef enum {
MAPCACHE_DIMENSION_VALUES,
MAPCACHE_DIMENSION_REGEX,
MAPCACHE_DIMENSION_POSTGRESQL,
MAPCACHE_DIMENSION_SQLITE,
MAPCACHE_DIMENSION_ELASTICSEARCH
} mapcache_dimension_type;
typedef enum {
MAPCACHE_DIMENSION_ASSEMBLY_NONE,
MAPCACHE_DIMENSION_ASSEMBLY_STACK,
MAPCACHE_DIMENSION_ASSEMBLY_ANIMATE
} mapcache_dimension_assembly_type;
/** \defgroup utility Utility */
/** @{ */
struct mapcache_extent {
double minx;
double miny;
double maxx;
double maxy;
};
struct mapcache_extent_i {
int minx;
int miny;
int maxx;
int maxy;
};
mapcache_image *mapcache_error_image(mapcache_context *ctx, int width, int height, char *msg);
/**
* \interface mapcache_context
* \brief structure passed to most mapcache functions to abstract common functions
*/
struct mapcache_context {
/**
* \brief indicate that an error has happened
* \memberof mapcache_context
* \param c
* \param code the error code
* \param message human readable message of what happened
*/
void (*set_error)(mapcache_context *ctx, int code, char *message, ...);
void (*set_exception)(mapcache_context *ctx, char *key, char *message, ...);
/**
* \brief query context to know if an error has occurred
* \memberof mapcache_context
*/
int (*get_error)(mapcache_context * ctx);
/**
* \brief get human readable message for the error
* \memberof mapcache_context
*/
char* (*get_error_message)(mapcache_context * ctx);
/**
* \brief get human readable message for the error
* \memberof mapcache_context
*/
void (*clear_errors)(mapcache_context * ctx);
/**
* \brief clear current error and store it in mapcache_error
* \memberof mapcache_context
*/
void (*pop_errors)(mapcache_context * ctx, void **error);
/**
* \brief restore error status from mapcache_error
* \memberof mapcache_context
*/
void (*push_errors)(mapcache_context * ctx, void *error);
/**
* \brief log a message
* \memberof mapcache_context
*/
void (*log)(mapcache_context *ctx, mapcache_log_level level, char *message, ...);
const char* (*get_instance_id)(mapcache_context * ctx);
mapcache_context* (*clone)(mapcache_context *ctx);
apr_pool_t *pool;
mapcache_connection_pool *connection_pool;
char *_contenttype;
char *_errmsg;
int _errcode;
mapcache_cfg *config;
mapcache_service *service;
apr_table_t *exceptions;
int supports_redirects;
apr_table_t *headers_in;
};
MS_DLL_EXPORT void mapcache_context_init(mapcache_context *ctx);
MS_DLL_EXPORT void mapcache_context_copy(mapcache_context *src, mapcache_context *dst);
#define GC_CHECK_ERROR_RETURN(ctx) if(((mapcache_context*)ctx)->_errcode) return MAPCACHE_FAILURE;
#define GC_CHECK_ERROR(ctx) if(((mapcache_context*)ctx)->_errcode) return;
#define GC_HAS_ERROR(ctx) (((mapcache_context*)ctx)->_errcode > 0)
/**
* \brief autoexpanding buffer that allocates memory from a pool
* \sa mapcache_buffer_create()
* \sa mapcache_buffer_append()
*
*/
struct mapcache_buffer {
void* buf; /**< pointer to the actual data contained in buffer */
size_t size; /**< number of bytes actually used in the buffer */
size_t avail; /**< number of bytes allocated */
apr_pool_t* pool; /**< apache pool to allocate from */
};
/* in buffer.c */
/**
* \brief create and initialize a mapcache_buffer
* \memberof mapcache_buffer
* \param initialStorage the initial size that should be allocated in the buffer.
* defaults to #INITIAL_BUFFER_SIZE.
* \param pool the pool from which to allocate memory.
*/
mapcache_buffer *mapcache_buffer_create(size_t initialStorage, apr_pool_t* pool);
/**
* \brief append data
* \memberof mapcache_buffer
* \param buffer
* \param len the lenght of the data to append.
* \param data the data to append
*/
int mapcache_buffer_append(mapcache_buffer *buffer, size_t len, void *data);
/** @} */
/** \defgroup source Sources */
/** @{ */
typedef enum {
MAPCACHE_SOURCE_WMS,
MAPCACHE_SOURCE_MAPSERVER,
MAPCACHE_SOURCE_DUMMY,
MAPCACHE_SOURCE_GDAL,
MAPCACHE_SOURCE_FALLBACK
} mapcache_source_type;
/**\interface mapcache_source
* \brief a source of data that can return image data
*/
struct mapcache_source {
char *name; /**< the key this source can be referenced by */
mapcache_extent data_extent; /**< extent in which this source can produce data */
mapcache_source_type type;
apr_table_t *metadata;
unsigned int retry_count;
double retry_delay;
apr_array_header_t *info_formats;
/**
* \brief get the data for the metatile
*
* sets the mapcache_metatile::tile::data for the given tile
*/
void (*_render_map)(mapcache_context *ctx, mapcache_source *psource, mapcache_map *map);
void (*_query_info)(mapcache_context *ctx, mapcache_source *psource, mapcache_feature_info *fi);
void (*configuration_parse_xml)(mapcache_context *ctx, ezxml_t xml, mapcache_source * source, mapcache_cfg *config);
void (*configuration_check)(mapcache_context *ctx, mapcache_cfg *cfg, mapcache_source * source);
};
mapcache_http* mapcache_http_configuration_parse_xml(mapcache_context *ctx,ezxml_t node);
mapcache_http* mapcache_http_clone(mapcache_context *ctx, mapcache_http *orig);
struct mapcache_http {
char *url; /**< the base url to request */
apr_table_t *headers; /**< additional headers to add to the http request, eg, Referer */
char *post_body;
size_t post_len;
int connection_timeout;
int timeout;
/* TODO: authentication */
};
/** \defgroup cache Caches */
/** @{ */
typedef enum {
MAPCACHE_CACHE_DISK
,MAPCACHE_CACHE_REST
,MAPCACHE_CACHE_MEMCACHE
,MAPCACHE_CACHE_SQLITE
,MAPCACHE_CACHE_BDB
,MAPCACHE_CACHE_TC
,MAPCACHE_CACHE_TIFF
,MAPCACHE_CACHE_COMPOSITE
,MAPCACHE_CACHE_COUCHBASE
,MAPCACHE_CACHE_RIAK
} mapcache_cache_type;
/** \interface mapcache_cache
* \brief a place to cache a mapcache_tile
*/
struct mapcache_cache {
char *name; /**< key this cache is referenced by */
mapcache_cache_type type;
apr_table_t *metadata;
unsigned int retry_count;
double retry_delay;
/**
* get tile content from cache
* \returns MAPCACHE_SUCCESS if the data was correctly loaded from the cache
* \returns MAPCACHE_FAILURE if the file exists but contains no data
* \returns MAPCACHE_CACHE_MISS if the file does not exist on the cache
* \memberof mapcache_cache
*/
int (*_tile_get)(mapcache_context *ctx, mapcache_cache *cache, mapcache_tile * tile);
/**
* delete tile from cache
*
* \memberof mapcache_cache
*/
void (*_tile_delete)(mapcache_context *ctx, mapcache_cache *cache, mapcache_tile * tile);
int (*_tile_exists)(mapcache_context *ctx, mapcache_cache *cache, mapcache_tile * tile);
/**
* set tile content to cache
* \memberof mapcache_cache
*/
void (*_tile_set)(mapcache_context *ctx, mapcache_cache *cache, mapcache_tile * tile);
void (*_tile_multi_set)(mapcache_context *ctx, mapcache_cache *cache, mapcache_tile *tiles, int ntiles);
void (*configuration_parse_xml)(mapcache_context *ctx, ezxml_t xml, mapcache_cache * cache, mapcache_cfg *config);
void (*configuration_post_config)(mapcache_context *ctx, mapcache_cache * cache, mapcache_cfg *config);
};
MS_DLL_EXPORT int mapcache_cache_tile_get(mapcache_context *ctx, mapcache_cache *cache, mapcache_tile *tile);
void mapcache_cache_tile_delete(mapcache_context *ctx, mapcache_cache *cache, mapcache_tile *tile);
MS_DLL_EXPORT int mapcache_cache_tile_exists(mapcache_context *ctx, mapcache_cache *cache, mapcache_tile *tile);
MS_DLL_EXPORT void mapcache_cache_tile_set(mapcache_context *ctx, mapcache_cache *cache, mapcache_tile *tile);
void mapcache_cache_tile_multi_set(mapcache_context *ctx, mapcache_cache *cache, mapcache_tile *tiles, int ntiles);
/**
* \memberof mapcache_cache_sqlite
*/
mapcache_cache* mapcache_cache_sqlite_create(mapcache_context *ctx);
mapcache_cache* mapcache_cache_mbtiles_create(mapcache_context *ctx);
/**
* \memberof mapcache_cache_bdb
*/
mapcache_cache *mapcache_cache_bdb_create(mapcache_context *ctx);
/**
* \memberof mapcache_cache_memcache
*/
mapcache_cache* mapcache_cache_memcache_create(mapcache_context *ctx);
/**
* \memberof mapcache_cache_couchbase
*/
mapcache_cache* mapcache_cache_couchbase_create(mapcache_context *ctx);
/**
* \memberof mapcache_cache_tc
*/
mapcache_cache* mapcache_cache_tc_create(mapcache_context *ctx);
/**
* \memberof mapcache_cache_riak
*/
mapcache_cache* mapcache_cache_riak_create(mapcache_context *ctx);
/** @} */
typedef enum {
MAPCACHE_REQUEST_UNKNOWN,
MAPCACHE_REQUEST_GET_TILE,
MAPCACHE_REQUEST_GET_MAP,
MAPCACHE_REQUEST_GET_CAPABILITIES,
MAPCACHE_REQUEST_GET_FEATUREINFO,
MAPCACHE_REQUEST_PROXY
} mapcache_request_type;
typedef enum {
MAPCACHE_GETMAP_ERROR,
MAPCACHE_GETMAP_ASSEMBLE,
MAPCACHE_GETMAP_FORWARD
} mapcache_getmap_strategy;
typedef enum {
MAPCACHE_RESAMPLE_NEAREST,
MAPCACHE_RESAMPLE_BILINEAR
} mapcache_resample_mode;
/**
* \brief a request sent by a client
*/
struct mapcache_request {
mapcache_request_type type;
mapcache_service *service;
};
struct mapcache_request_image {
mapcache_request request;
mapcache_image_format *format;
};
struct mapcache_request_get_tile {
mapcache_request_image image_request;
/**
* a list of tiles requested by the client
*/
mapcache_tile **tiles;
/**
* the number of tiles requested by the client.
* If more than one, and merging is enabled,
* the supplied tiles will be merged together
* before being returned to the client
*/
int ntiles;
int allow_redirect;
};
struct mapcache_http_response {
mapcache_buffer *data;
apr_table_t *headers;
long code;
apr_time_t mtime;
};
struct mapcache_map {
mapcache_tileset *tileset;
mapcache_grid_link *grid_link;
apr_array_header_t *dimensions;
mapcache_buffer *encoded_data;
mapcache_image *raw_image;
int nodata; /**< \sa mapcache_tile::nodata */
int width, height;
mapcache_extent extent;
apr_time_t mtime; /**< last modification time */
int expires; /**< time in seconds after which the tile should be rechecked for validity */
};
struct mapcache_feature_info {
mapcache_map map;
int i,j;
char *format;
mapcache_buffer *data;
};
struct mapcache_request_get_feature_info {
mapcache_request request;
mapcache_feature_info *fi;
};
struct mapcache_request_get_map {
mapcache_request_image image_request;
mapcache_map **maps;
int nmaps;
mapcache_getmap_strategy getmap_strategy;
mapcache_resample_mode resample_mode;
};
struct mapcache_request_get_capabilities {
mapcache_request request;
/**
* the body of the capabilities
*/
char *capabilities;
/**
* the mime type
*/
char *mime_type;
};
struct mapcache_forwarding_rule {
char *name;
mapcache_http *http;
apr_array_header_t *match_params; /* actually those are mapcache_dimensions */
int append_pathinfo;
size_t max_post_len;
};
struct mapcache_request_proxy {
mapcache_request request;
mapcache_forwarding_rule *rule;
apr_table_t *params;
apr_table_t *headers;
const char *pathinfo;
char *post_buf;
size_t post_len;
};
/** \defgroup services Services*/
/** @{ */
#define MAPCACHE_SERVICES_COUNT 8
typedef enum {
MAPCACHE_SERVICE_TMS=0, MAPCACHE_SERVICE_WMTS,
MAPCACHE_SERVICE_DEMO, MAPCACHE_SERVICE_GMAPS, MAPCACHE_SERVICE_KML,
MAPCACHE_SERVICE_VE, MAPCACHE_SERVICE_MAPGUIDE, MAPCACHE_SERVICE_WMS
} mapcache_service_type;
#define MAPCACHE_UNITS_COUNT 3
typedef enum {
MAPCACHE_UNIT_METERS=0, MAPCACHE_UNIT_DEGREES, MAPCACHE_UNIT_FEET
} mapcache_unit;
/* defined in util.c*/
extern const double mapcache_meters_per_unit[MAPCACHE_UNITS_COUNT];
/** \interface mapcache_service
* \brief a standard service (eg WMS, TMS)
*/
struct mapcache_service {
char *name;
mapcache_service_type type;
/**
* the pathinfo prefix of the url that routes to this service
* eg, for accessing a wms service on http://host/mapcache/mywmsservice? ,
* url_prefix would take the value "mywmsservice"
*/
char *url_prefix;
/**
* \brief allocates and populates a mapcache_request corresponding to the parameters received
*/
void (*parse_request)(mapcache_context *ctx, mapcache_service *service, mapcache_request **request, const char *path_info, apr_table_t *params, mapcache_cfg * config);
/**
* \param request the received request (should be of type MAPCACHE_REQUEST_CAPABILITIES
* \param url the full url at which the service is available
*/
void (*create_capabilities_response)(mapcache_context *ctx, mapcache_request_get_capabilities *request, char *url, char *path_info, mapcache_cfg *config);
/**
* parse advanced configuration options for the selected service
*/
void (*configuration_parse_xml)(mapcache_context *ctx, ezxml_t xml, mapcache_service * service, mapcache_cfg *config);
void (*format_error)(mapcache_context *ctx, mapcache_service * service, char *err_msg,
char **err_body, apr_table_t *headers);
};
/**
* \brief create and initialize a mapcache_service_wms
* \memberof mapcache_service_wms
*/
mapcache_service* mapcache_service_wms_create(mapcache_context *ctx);
/**
* \brief create and initialize a mapcache_service_ve
* \memberof mapcache_service_ve
*/
mapcache_service* mapcache_service_ve_create(mapcache_context *ctx);
/**
* \brief create and initialize a mapcache_service_mapguide
* \memberof mapcache_service_mapguide
*/
mapcache_service* mapcache_service_mapguide_create(mapcache_context *ctx);
/**
* \brief create and initialize a mapcache_service_gmaps
* \memberof mapcache_service_gmaps
*/
mapcache_service* mapcache_service_gmaps_create(mapcache_context *ctx);
/**
* \brief create and initialize a mapcache_service_kml
* \memberof mapcache_service_kml
*/
mapcache_service* mapcache_service_kml_create(mapcache_context *ctx);
/**
* \brief create and initialize a mapcache_service_tms
* \memberof mapcache_service_tms
*/
mapcache_service* mapcache_service_tms_create(mapcache_context *ctx);
/**
* \brief create and initialize a mapcache_service_wmts
* \memberof mapcache_service_wtms
*/
mapcache_service* mapcache_service_wmts_create(mapcache_context *ctx);
/**
* \brief create and initialize a mapcache_service_demo
* \memberof mapcache_service_demo
*/
mapcache_service* mapcache_service_demo_create(mapcache_context *ctx);
/**
* \brief return the request that corresponds to the given url
*/
MS_DLL_EXPORT void mapcache_service_dispatch_request(mapcache_context *ctx,
mapcache_request **request,
char *pathinfo,
apr_table_t *params,
mapcache_cfg *config);
/**
* \brief return the number of enabled/configured services
*/
MS_DLL_EXPORT int mapcache_config_services_enabled(mapcache_context *ctx, mapcache_cfg *config);
/** @} */
/** \defgroup image Image Data Handling */
/** @{ */
typedef enum {
GC_UNKNOWN, GC_PNG, GC_JPEG, GC_RAW
} mapcache_image_format_type;
typedef enum {
MC_EMPTY_UNKNOWN, MC_EMPTY_YES, MC_EMPTY_NO
} mapcache_image_blank_type;
typedef enum {
MC_ALPHA_UNKNOWN, MC_ALPHA_YES, MC_ALPHA_NO
} mapcache_image_alpha_type;
/**\class mapcache_image
* \brief representation of an RGBA image
*
* to access a pixel at position x,y, you should use the #GET_IMG_PIXEL macro
*/
struct mapcache_image {
unsigned char *data; /**< pointer to the beginning of image data, stored in rgba order */
size_t w; /**< width of the image */
size_t h; /**< height of the image */
size_t stride; /**< stride of an image row */
mapcache_image_blank_type is_blank;
mapcache_image_alpha_type has_alpha;
};
/** \def GET_IMG_PIXEL
* return the address of a pixel
* \param y the row
* \param x the column
* \param img the mapcache_image
* \returns a pointer to the pixel
*/
#define GET_IMG_PIXEL(img,x,y) (&((img).data[(y)*(img).stride + (x)*4]))
/**
* \brief initialize a new mapcache_image
*/
mapcache_image* mapcache_image_create(mapcache_context *ctx);
mapcache_image* mapcache_image_create_with_data(mapcache_context *ctx, int width, int height);
void mapcache_image_copy_resampled_nearest(mapcache_context *ctx, mapcache_image *src, mapcache_image *dst,
double off_x, double off_y, double scale_x, double scale_y);
void mapcache_image_copy_resampled_bilinear(mapcache_context *ctx, mapcache_image *src, mapcache_image *dst,
double off_x, double off_y, double scale_x, double scale_y, int reflect_edges);
/**
* \brief merge two images
* \param base the imae to merge onto
* \param overlay the image to overlay onto
* \param ctx the context
* when finished, base will be modified and have overlay merged onto it
*/
void mapcache_image_merge(mapcache_context *ctx, mapcache_image *base, mapcache_image *overlay);
void mapcache_image_copy_resampled(mapcache_context *ctx, mapcache_image *src, mapcache_image *dst,
int srcX, int srcY, int srcW, int srcH,
int dstX, int dstY, int dstW, int dstH);
/**
* \brief split the given metatile into tiles
* \param mt the metatile to split
* \param r the context
*/
void mapcache_image_metatile_split(mapcache_context *ctx, mapcache_metatile *mt);
/**
* \brief check if given image is composed of a unique color
* \param image the mapcache_image to process
* \returns MAPCACHE_TRUE if the image contains a single color
* \returns MAPCACHE_FALSE if the image has more than one color
*/
int mapcache_image_blank_color(mapcache_image* image);
/**
* \brief check if image has some non opaque pixels
*/
int mapcache_image_has_alpha(mapcache_image *img, unsigned int cutoff);
void mapcache_image_fill(mapcache_context *ctx, mapcache_image *image, const unsigned char *fill_color);
/** @} */
/** \defgroup http HTTP Request handling*/
/** @{ */
void mapcache_http_do_request(mapcache_context *ctx, mapcache_http *req, mapcache_buffer *data, apr_table_t *headers, long *http_code);
char* mapcache_http_build_url(mapcache_context *ctx, char *base, apr_table_t *params);
MS_DLL_EXPORT apr_table_t *mapcache_http_parse_param_string(mapcache_context *ctx, char *args);
/** @} */
/** \defgroup configuration Configuration*/
/** @{ */
typedef enum {
MAPCACHE_MODE_NORMAL,
MAPCACHE_MODE_MIRROR_COMBINED,
MAPCACHE_MODE_MIRROR_SPLIT
} mapcache_mode;
typedef enum {
MAPCACHE_LOCKER_DISK,
MAPCACHE_LOCKER_MEMCACHE,
MAPCACHE_LOCKER_FALLBACK
} mapcache_lock_mode;
typedef enum {
MAPCACHE_LOCK_AQUIRED,
MAPCACHE_LOCK_LOCKED,
MAPCACHE_LOCK_NOENT
} mapcache_lock_result;
struct mapcache_locker{
mapcache_lock_result (*aquire_lock)(mapcache_context *ctx, mapcache_locker *self, char *resource, void **lock);
mapcache_lock_result (*ping_lock)(mapcache_context *ctx, mapcache_locker *self, void *lock);
void (*release_lock)(mapcache_context *ctx, mapcache_locker *self, void *lock);
void (*parse_xml)(mapcache_context *ctx, mapcache_locker *self, ezxml_t node);
mapcache_lock_mode type;
double timeout;
double retry_interval; /* time to wait before checking again on a lock, in seconds */
};
mapcache_locker* mapcache_locker_disk_create(mapcache_context *ctx);
mapcache_locker* mapcache_locker_memcache_create(mapcache_context *ctx);
mapcache_locker* mapcache_locker_fallback_create(mapcache_context *ctx);
void mapcache_config_parse_locker(mapcache_context *ctx, ezxml_t node, mapcache_locker **locker);
void mapcache_config_parse_locker_old(mapcache_context *ctx, ezxml_t doc, mapcache_cfg *config);
/**
* a configuration that will be served
*/
struct mapcache_cfg {
/**
* a list of services that will be responded to
*/
mapcache_service * services[MAPCACHE_SERVICES_COUNT];
/**
* hashtable containing configured mapcache_source%s
*/
apr_hash_t *sources;
/**
* hashtable containing configured mapcache_cache%s
*/
apr_hash_t *caches;
/**
* hashtable containing configured mapcache_tileset%s
*/
apr_hash_t *tilesets;
/**
* hashtable containing configured mapcache_image_format%s
*/
apr_hash_t *image_formats;
/**
* hashtable containing (pre)defined grids
*/
apr_hash_t *grids;
/**
* the format to use for some miscelaneaous operations:
* - creating an empty image
* - creating an error image
* - as a fallback when merging multiple tiles
*/
mapcache_image_format *default_image_format;
/**
* how should error messages be reported to the user
*/
mapcache_error_reporting reporting;
/**
* encoded empty (tranpsarent) image that will be returned to clients if cofigured
* to return blank images upon error
*/
mapcache_buffer *empty_image;
apr_table_t *metadata;
mapcache_locker *locker;
int threaded_fetching;
/* for fastcgi only */
int autoreload; /* should the modification time of the config file be recorded
and the file be reparsed if it is modified. */
mapcache_log_level loglevel; /* logging verbosity. Ignored for the apache module
as in that case the apache LogLevel directive is
used. */
mapcache_mode mode;
/* return 404 on potentially blocking operations (proxying, source getmaps,
locks on metatile waiting, ... Used for nginx module */
int non_blocking;
// Parameters for connection_pool:
// - cp_hmax defines the maximum number of open connections at the same time
// - cp_ttl defines the maximum amount of time in microseconds an unused connection is valid
int cp_hmax;
int cp_ttl;
};
/**
*
* @param filename
* @param config
* @param pool
* @return
*/
MS_DLL_EXPORT void mapcache_configuration_parse(mapcache_context *ctx, const char *filename, mapcache_cfg *config, int cgi);
MS_DLL_EXPORT void mapcache_configuration_post_config(mapcache_context *ctx, mapcache_cfg *config);
void mapcache_configuration_parse_xml(mapcache_context *ctx, const char *filename, mapcache_cfg *config);
MS_DLL_EXPORT mapcache_cfg* mapcache_configuration_create(apr_pool_t *pool);
mapcache_source* mapcache_configuration_get_source(mapcache_cfg *config, const char *key);
MS_DLL_EXPORT mapcache_cache* mapcache_configuration_get_cache(mapcache_cfg *config, const char *key);
mapcache_grid *mapcache_configuration_get_grid(mapcache_cfg *config, const char *key);
MS_DLL_EXPORT mapcache_tileset* mapcache_configuration_get_tileset(mapcache_cfg *config, const char *key);
mapcache_image_format *mapcache_configuration_get_image_format(mapcache_cfg *config, const char *key);
void mapcache_configuration_add_image_format(mapcache_cfg *config, mapcache_image_format *format, const char * key);
void mapcache_configuration_add_source(mapcache_cfg *config, mapcache_source *source, const char * key);
void mapcache_configuration_add_grid(mapcache_cfg *config, mapcache_grid *grid, const char * key);
void mapcache_configuration_add_tileset(mapcache_cfg *config, mapcache_tileset *tileset, const char * key);
void mapcache_configuration_add_cache(mapcache_cfg *config, mapcache_cache *cache, const char * key);
/** @} */
/**
* \memberof mapcache_source
*/
void mapcache_source_init(mapcache_context *ctx, mapcache_source *source);
/**
* \memberof mapcache_source
*/
void mapcache_source_render_map(mapcache_context *ctx, mapcache_source *source, mapcache_map *map);
void mapcache_source_query_info(mapcache_context *ctx, mapcache_source *source,
mapcache_feature_info *fi);
/**
* \memberof mapcache_source_gdal
*/
mapcache_source* mapcache_source_gdal_create(mapcache_context *ctx);
/**
* \memberof mapcache_source_fallback
*/
mapcache_source* mapcache_source_fallback_create(mapcache_context *ctx);
/**
* \memberof mapcache_source_wms
*/
mapcache_source* mapcache_source_wms_create(mapcache_context *ctx);
/**
* \memberof mapcache_source_wms
*/
mapcache_source* mapcache_source_mapserver_create(mapcache_context *ctx);
mapcache_source* mapcache_source_dummy_create(mapcache_context *ctx);
/**
* \memberof mapcache_cache_disk
*/
mapcache_cache* mapcache_cache_disk_create(mapcache_context *ctx);
/**
* \memberof mapcache_cache_rest
*/
mapcache_cache* mapcache_cache_rest_create(mapcache_context *ctx);
mapcache_cache* mapcache_cache_s3_create(mapcache_context *ctx);
mapcache_cache* mapcache_cache_azure_create(mapcache_context *ctx);
mapcache_cache* mapcache_cache_google_create(mapcache_context *ctx);
/**
* \memberof mapcache_cache_tiff
*/
mapcache_cache* mapcache_cache_tiff_create(mapcache_context *ctx);
mapcache_cache* mapcache_cache_composite_create(mapcache_context *ctx);
mapcache_cache* mapcache_cache_fallback_create(mapcache_context *ctx);
mapcache_cache* mapcache_cache_multitier_create(mapcache_context *ctx);
/** \defgroup tileset Tilesets*/
/** @{ */
/**
* \brief Tile
* \sa mapcache_metatile
* \sa mapcache_tileset::metasize_x mapcache_tileset::metasize_x mapcache_tileset::metabuffer
*/
struct mapcache_tile {
mapcache_tileset *tileset; /**< the mapcache_tileset that corresponds to the tile*/
mapcache_grid_link *grid_link;
int x; /**< tile x index */
int y; /**< tile y index */
int z; /**< tile z index (zoom level) */
/**
* encoded image data for the tile.
* \sa mapcache_cache::tile_get()
* \sa mapcache_source::render_map()
* \sa mapcache_image_format
*/
mapcache_buffer *encoded_data;
char *redirect;
int allow_redirect;
mapcache_image *raw_image;
apr_time_t mtime; /**< last modification time */
int expires; /**< time in seconds after which the tile should be rechecked for validity */
apr_array_header_t *dimensions;
/**
* flag stating the tile is empty (i.e. fully transparent).
* if set, this indicates that there was no error per se, but that there was
* no way to get data back from the cache for this tile. This will happen for
* a tileset with no <source> configured, for tiles that have not been preseeded.
* Tile assembling functions should look for this flag and ignore such a tile when