-
-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathmapcache.h
More file actions
1795 lines (1489 loc) · 53 KB
/
mapcache.h
File metadata and controls
1795 lines (1489 loc) · 53 KB
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
/******************************************************************************
* $Id$
*
* Project: MapServer
* 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 "util.h"
#include "ezxml.h"
#include "errors.h"
#if 0
#ifdef USE_GDAL
#include <gdal.h>
#include <cpl_conv.h>
#endif
#endif
#include <assert.h>
#include <time.h>
#include <apr_time.h>
#ifdef USE_PCRE
#include <pcre.h>
#else
#include <regex.h>
#endif
#ifdef USE_MEMCACHE
#include <apr_memcache.h>
#endif
#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_USERAGENT "mod-mapcache/"MAPCACHE_VERSION
#define MAPCACHE_LOCKFILE_PREFIX "_gc_lock"
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_gif mapcache_image_format_gif;
typedef struct mapcache_image_format_jpeg mapcache_image_format_jpeg;
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_source_wms mapcache_source_wms;
#if 0
typedef struct mapcache_source_gdal mapcache_source_gdal;
#endif
typedef struct mapcache_cache_disk mapcache_cache_disk;
#ifdef USE_TIFF
typedef struct mapcache_cache_tiff mapcache_cache_tiff;
#endif
typedef struct mapcache_http mapcache_http;
typedef struct mapcache_request mapcache_request;
typedef struct mapcache_request_proxy mapcache_request_proxy;
typedef struct mapcache_request_get_capabilities mapcache_request_get_capabilities;
typedef struct mapcache_request_get_capabilities_demo mapcache_request_get_capabilities_demo;
typedef struct mapcache_request_get_capabilities_wms mapcache_request_get_capabilities_wms;
typedef struct mapcache_request_get_capabilities_wmts mapcache_request_get_capabilities_wmts;
typedef struct mapcache_forwarding_rule mapcache_forwarding_rule;
typedef struct mapcache_request_get_capabilities_tms mapcache_request_get_capabilities_tms;
typedef struct mapcache_request_get_capabilities_kml mapcache_request_get_capabilities_kml;
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_service_wms mapcache_service_wms;
typedef struct mapcache_service_wmts mapcache_service_wmts;
typedef struct mapcache_service_gmaps mapcache_service_gmaps;
typedef struct mapcache_service_ve mapcache_service_ve;
typedef struct mapcache_service_tms mapcache_service_tms;
typedef struct mapcache_service_kml mapcache_service_kml;
typedef struct mapcache_service_mapguide mapcache_service_mapguide;
typedef struct mapcache_service_demo mapcache_service_demo;
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_dimension_time mapcache_dimension_time;
typedef struct mapcache_timedimension mapcache_timedimension;
typedef struct mapcache_dimension_intervals mapcache_dimension_intervals;
typedef struct mapcache_dimension_values mapcache_dimension_values;
typedef struct mapcache_dimension_regex mapcache_dimension_regex;
typedef struct mapcache_extent mapcache_extent;
typedef struct mapcache_extent_i mapcache_extent_i;
/** \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 occured
* \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 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;
apr_pool_t *process_pool;
void *threadlock;
char *_contenttype;
char *_errmsg;
int _errcode;
mapcache_cfg *config;
mapcache_service *service;
apr_table_t *exceptions;
};
void mapcache_context_init(mapcache_context *ctx);
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_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;
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_map *map);
void (*query_info)(mapcache_context *ctx, mapcache_feature_info *fi);
void (*configuration_parse_xml)(mapcache_context *ctx, ezxml_t xml, mapcache_source * source);
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 */
int connection_timeout;
int timeout;
/* TODO: authentication */
};
/**\class mapcache_source_wms
* \brief WMS mapcache_source
* \implements mapcache_source
*/
struct mapcache_source_wms {
mapcache_source source;
apr_table_t *wms_default_params; /**< default WMS parameters (SERVICE,REQUEST,STYLES,VERSION) */
apr_table_t *getmap_params; /**< WMS parameters specified in configuration */
apr_table_t *getfeatureinfo_params; /**< WMS parameters specified in configuration */
mapcache_http *http;
};
#ifdef USE_MAPSERVER
/**\class mapcache_source_mapserver
* \brief WMS mapcache_source
* \implements mapcache_source
*/
typedef struct mapcache_source_mapserver mapcache_source_mapserver;
struct mapcache_source_mapserver {
mapcache_source source;
char *mapfile;
};
#endif
typedef struct mapcache_source_dummy mapcache_source_dummy;
struct mapcache_source_dummy {
mapcache_source source;
char *mapfile;
void *mapobj;
};
#if 0
#ifdef USE_GDAL
/**\class mapcache_source_gdal
* \brief GDAL mapcache_source
* \implements mapcache_source
*/
struct mapcache_source_gdal {
mapcache_source source;
char *datastr; /**< the gdal source string*/
apr_table_t *gdal_params; /**< GDAL parameters specified in configuration */
GDALDatasetH *poDataset;
};
#endif
/** @} */
#endif
/** \defgroup cache Caches */
/** @{ */
typedef enum {
MAPCACHE_CACHE_DISK
#ifdef USE_MEMCACHE
,MAPCACHE_CACHE_MEMCACHE
#endif
#ifdef USE_SQLITE
,MAPCACHE_CACHE_SQLITE
#endif
#ifdef USE_BDB
,MAPCACHE_CACHE_BDB
#endif
#ifdef USE_TC
,MAPCACHE_CACHE_TC
#endif
#ifdef USE_TIFF
,MAPCACHE_CACHE_TIFF
#endif
} 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;
/**
* get tile content from cache
* \returns MAPCACHE_SUCCESS if the data was correctly loaded from the disk
* \returns MAPCACHE_FAILURE if the file exists but contains no data
* \returns MAPCACHE_CACHE_MISS if the file does not exist on the disk
* \memberof mapcache_cache
*/
int (*tile_get)(mapcache_context *ctx, mapcache_tile * tile);
/**
* delete tile from cache
*
* \memberof mapcache_cache
*/
void (*tile_delete)(mapcache_context *ctx, mapcache_tile * tile);
int (*tile_exists)(mapcache_context *ctx, mapcache_tile * tile);
/**
* set tile content to cache
* \memberof mapcache_cache
*/
void (*tile_set)(mapcache_context *ctx, mapcache_tile * tile);
void (*tile_multi_set)(mapcache_context *ctx, 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);
};
/**\class mapcache_cache_disk
* \brief a mapcache_cache on a filesytem
* \implements mapcache_cache
*/
struct mapcache_cache_disk {
mapcache_cache cache;
char *base_directory;
char *filename_template;
int symlink_blank;
int creation_retry;
/**
* Set filename for a given tile
* \memberof mapcache_cache_disk
*/
void (*tile_key)(mapcache_context *ctx, mapcache_tile *tile, char **path);
};
#ifdef USE_TIFF
struct mapcache_cache_tiff {
mapcache_cache cache;
char *filename_template;
char *x_fmt,*y_fmt,*z_fmt,*inv_x_fmt,*inv_y_fmt,*div_x_fmt,*div_y_fmt,*inv_div_x_fmt,*inv_div_y_fmt;
int count_x;
int count_y;
mapcache_image_format_jpeg *format;
};
#endif
#ifdef USE_SQLITE
/**\class mapcache_cache_sqlite
* \brief a mapcache_cache on a filesytem
* \implements mapcache_cache
*/
typedef struct mapcache_cache_sqlite mapcache_cache_sqlite;
typedef struct mapcache_cache_sqlite_stmt mapcache_cache_sqlite_stmt;
struct mapcache_cache_sqlite_stmt {
char *sql;
};
struct mapcache_cache_sqlite {
mapcache_cache cache;
char *dbfile;
mapcache_cache_sqlite_stmt create_stmt;
mapcache_cache_sqlite_stmt exists_stmt;
mapcache_cache_sqlite_stmt get_stmt;
mapcache_cache_sqlite_stmt set_stmt;
mapcache_cache_sqlite_stmt delete_stmt;
apr_table_t *pragmas;
void (*bind_stmt)(mapcache_context*ctx, void *stmt, mapcache_tile *tile);
int n_prepared_statements;
int detect_blank;
};
/**
* \memberof mapcache_cache_sqlite
*/
mapcache_cache* mapcache_cache_sqlite_create(mapcache_context *ctx);
mapcache_cache* mapcache_cache_mbtiles_create(mapcache_context *ctx);
#endif
#ifdef USE_BDB
typedef struct mapcache_cache_bdb mapcache_cache_bdb;
struct mapcache_cache_bdb {
mapcache_cache cache;
char *basedir;
char *key_template;
};
mapcache_cache *mapcache_cache_bdb_create(mapcache_context *ctx);
#endif
#ifdef USE_TC
typedef struct mapcache_cache_tc mapcache_cache_tc;
struct mapcache_cache_tc {
mapcache_cache cache;
char *basedir;
char *key_template;
mapcache_context *ctx;
};
mapcache_cache *mapcache_cache_tc_create(mapcache_context *ctx);
#endif
#ifdef USE_MEMCACHE
typedef struct mapcache_cache_memcache mapcache_cache_memcache;
/**\class mapcache_cache_memcache
* \brief a mapcache_cache on memcached servers
* \implements mapcache_cache
*/
struct mapcache_cache_memcache {
mapcache_cache cache;
apr_memcache_t *memcache;
};
/**
* \memberof mapcache_cache_memcache
*/
mapcache_cache* mapcache_cache_memcache_create(mapcache_context *ctx);
#endif
/** @} */
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_get_tile {
mapcache_request 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;
mapcache_image_format *format;
};
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_table_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 request;
mapcache_map **maps;
int nmaps;
mapcache_getmap_strategy getmap_strategy;
mapcache_resample_mode resample_mode;
mapcache_image_format *getmap_format;
};
struct mapcache_request_get_capabilities {
mapcache_request request;
/**
* the body of the capabilities
*/
char *capabilities;
/**
* the mime type
*/
char *mime_type;
};
struct mapcache_request_get_capabilities_tms {
mapcache_request_get_capabilities request;
mapcache_tileset *tileset;
mapcache_grid_link *grid_link;
char *version;
};
struct mapcache_request_get_capabilities_kml {
mapcache_request_get_capabilities request;
mapcache_tile *tile;
mapcache_tileset *tileset;
mapcache_grid_link *grid;
};
struct mapcache_request_get_capabilities_wms {
mapcache_request_get_capabilities request;
};
struct mapcache_request_get_capabilities_wmts {
mapcache_request_get_capabilities request;
};
/**
* the capabilities request for a specific service, to be able to create
* demo pages specific to a given service
*/
struct mapcache_request_get_capabilities_demo {
mapcache_request_get_capabilities request;
mapcache_service *service;
};
struct mapcache_request_proxy {
mapcache_request request;
mapcache_http *http;
apr_table_t *params;
const char *pathinfo;
};
struct mapcache_forwarding_rule {
char *name;
mapcache_http *http;
apr_array_header_t *match_params; /* actually those are mapcache_dimensions */
int append_pathinfo;
};
/** \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);
};
/**\class mapcache_service_wms
* \brief an OGC WMS service
* \implements mapcache_service
*/
struct mapcache_service_wms {
mapcache_service service;
int maxsize;
apr_array_header_t *forwarding_rules;
mapcache_getmap_strategy getmap_strategy;
mapcache_resample_mode resample_mode;
mapcache_image_format *getmap_format;
};
/**\class mapcache_service_kml
* \brief a KML superoverlay service
* \implements mapcache_service
*/
struct mapcache_service_kml {
mapcache_service service;
};
/**\class mapcache_service_tms
* \brief a TMS service
* \implements mapcache_service
*/
struct mapcache_service_tms {
mapcache_service service;
int reverse_y;
};
struct mapcache_service_mapguide {
mapcache_service service;
int rows_per_folder;
int cols_per_folder;
};
/**\class mapcache_service_wmts
* \brief a WMTS service
* \implements mapcache_service
*/
struct mapcache_service_wmts {
mapcache_service service;
};
/**\class mapcache_service_demo
* \brief a demo service
* \implements mapcache_service
*/
struct mapcache_service_demo {
mapcache_service service;
};
/**\class mapcache_service_ve
* \brief a virtualearth service
* \implements mapcache_service
*/
struct mapcache_service_ve {
mapcache_service service;
};
/**
* \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
*/
void mapcache_service_dispatch_request(mapcache_context *ctx,
mapcache_request **request,
char *pathinfo,
apr_table_t *params,
mapcache_cfg *config);
/** @} */
/** \defgroup image Image Data Handling */
/** @{ */
typedef enum {
GC_UNKNOWN, GC_PNG, GC_JPEG, GC_GIF
} 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);
/** @} */
/** \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);
void mapcache_http_do_request_with_params(mapcache_context *ctx, mapcache_http *req, apr_table_t *params,
mapcache_buffer *data, apr_table_t *headers, long *http_code);
char* mapcache_http_build_url(mapcache_context *ctx, char *base, apr_table_t *params);
apr_table_t *mapcache_http_parse_param_string(mapcache_context *ctx, char *args);
/** @} */
/** \defgroup configuration Configuration*/
/** @{ */
struct mapcache_server_cfg {
apr_hash_t *aliases; /**< list of mapcache configurations aliased to a server uri */
};
typedef enum {
MAPCACHE_MODE_NORMAL,
MAPCACHE_MODE_MIRROR_COMBINED,
MAPCACHE_MODE_MIRROR_SPLIT
} mapcache_mode;
/**
* a configuration that will be served
*/
struct mapcache_cfg {
char *configFile; /**< the filename from which this configuration was loaded */
/**
* 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;