forked from MapServer/MapServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapwcs20.cpp
5006 lines (4343 loc) · 190 KB
/
mapwcs20.cpp
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
* Purpose: OpenGIS Web Coverage Server (WCS) 2.0 implementation.
* Author: Stephan Meissl <stephan.meissl@eox.at>
* Fabian Schindler <fabian.schindler@eox.at>
* and the MapServer team.
*
******************************************************************************
* Copyright (c) 2010, 2011 EOX IT Services GmbH, Austria
*
* 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.
****************************************************************************/
#include "mapserver-config.h"
#if defined(USE_WCS_SVR)
#include <assert.h>
#include "mapserver.h"
#include "maperror.h"
#include "mapthread.h"
#include "mapows.h"
#include "mapwcs.h"
#include "mapgdal.h"
#include <float.h>
#include "gdal.h"
#include "cpl_port.h"
#include "maptime.h"
#include "mapprimitive.h"
#include "cpl_string.h"
#include <string.h>
#if defined(USE_LIBXML2)
#include <libxml/tree.h>
#include "maplibxml2.h"
#include <libxml/parser.h>
#endif /* defined(USE_LIBXML2) */
#include <string>
/************************************************************************/
/* msXMLStripIndentation */
/************************************************************************/
static void msXMLStripIndentation(char* ptr)
{
/* Remove spaces between > and < to get properly indented result */
char* afterLastClosingBracket = NULL;
if( *ptr == ' ' )
afterLastClosingBracket = ptr;
while( *ptr != '\0' )
{
if( *ptr == '<' && afterLastClosingBracket != NULL )
{
memmove(afterLastClosingBracket, ptr, strlen(ptr) + 1);
ptr = afterLastClosingBracket;
}
else if( *ptr == '>' )
{
afterLastClosingBracket = ptr + 1;
}
else if( *ptr != ' ' && *ptr != '\n' )
afterLastClosingBracket = NULL;
ptr ++;
}
}
/************************************************************************/
/* msStringParseInteger() */
/* */
/* Tries to parse a string as a integer value. If not possible */
/* the value MS_WCS20_UNBOUNDED is stored as value. */
/* If no characters could be parsed, MS_FAILURE is returned. If at */
/* least some characters could be parsed, MS_DONE is returned and */
/* only if all characters could be parsed, MS_SUCCESS is returned. */
/************************************************************************/
static int msStringParseInteger(const char *string, int *dest)
{
char *parse_check;
*dest = (int)strtol(string, &parse_check, 0);
if(parse_check == string) {
return MS_FAILURE;
} else if(parse_check - strlen(string) != string) {
return MS_DONE;
}
return MS_SUCCESS;
}
/************************************************************************/
/* msStringParseDouble() */
/* */
/* Tries to parse a string as a double value. If not possible */
/* the value 0 is stored as value. */
/* If no characters could be parsed, MS_FAILURE is returned. If at */
/* least some characters could be parsed, MS_DONE is returned and */
/* only if all characters could be parsed, MS_SUCCESS is returned. */
/************************************************************************/
static int msStringParseDouble(const char *string, double *dest)
{
char *parse_check = NULL;
*dest = strtod(string, &parse_check);
if(parse_check == string) {
return MS_FAILURE;
} else if(parse_check - strlen(string) != string) {
return MS_DONE;
}
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSParseTimeOrScalar20() */
/* */
/* Parses a string, either as a time or a scalar value and */
/* writes the output into the timeScalarUnion. */
/************************************************************************/
static int msWCSParseTimeOrScalar20(timeScalarUnion *u, const char *string)
{
struct tm time;
if (string) {
while(*string == ' ')
string ++;
}
if (!string || strlen(string) == 0 || !u) {
msSetError(MS_WCSERR, "Invalid string", "msWCSParseTimeOrScalar20()");
return MS_WCS20_ERROR_VALUE;
}
/* if the string is equal to "*" it means the value
* of the interval is unbounded */
if (EQUAL(string, "*")) {
u->scalar = MS_WCS20_UNBOUNDED;
u->unbounded = 1;
return MS_WCS20_UNDEFINED_VALUE;
}
/* if returned a valid value, use it */
if (msStringParseDouble(string, &(u->scalar)) == MS_SUCCESS) {
return MS_WCS20_SCALAR_VALUE;
}
/* otherwise it might be a time value */
msTimeInit(&time);
if (msParseTime(string, &time) == MS_TRUE) {
u->time = mktime(&time);
return MS_WCS20_TIME_VALUE;
}
/* the value could neither be parsed as a double nor as a time value */
else {
msSetError(MS_WCSERR,
"String %s could not be parsed to a time or scalar value",
"msWCSParseTimeOrScalar20()",string);
return MS_WCS20_ERROR_VALUE;
}
}
/************************************************************************/
/* msWCSCreateSubsetObj20() */
/* */
/* Creates a new wcs20SubsetObj and initializes it to standard */
/* values. */
/************************************************************************/
static wcs20SubsetObjPtr msWCSCreateSubsetObj20()
{
wcs20SubsetObjPtr subset = (wcs20SubsetObjPtr) malloc(sizeof(wcs20SubsetObj));
MS_CHECK_ALLOC(subset, sizeof(wcs20SubsetObj), NULL);
subset->axis = NULL;
subset->crs = NULL;
subset->min.scalar = subset->max.scalar = MS_WCS20_UNBOUNDED;
subset->min.unbounded = subset->max.unbounded = 0;
subset->operation = MS_WCS20_SLICE;
return subset;
}
/************************************************************************/
/* msWCSFreeSubsetObj20() */
/* */
/* Frees a wcs20SubsetObj and releases all linked resources. */
/************************************************************************/
static void msWCSFreeSubsetObj20(wcs20SubsetObjPtr subset)
{
if (NULL == subset) {
return;
}
msFree(subset->axis);
msFree(subset->crs);
msFree(subset);
}
/************************************************************************/
/* msWCSCreateAxisObj20() */
/* */
/* Creates a new wcs20AxisObj and initializes it to standard */
/* values. */
/************************************************************************/
static wcs20AxisObjPtr msWCSCreateAxisObj20()
{
wcs20AxisObj *axis = (wcs20AxisObjPtr)malloc(sizeof(wcs20AxisObj));
MS_CHECK_ALLOC(axis, sizeof(wcs20AxisObj), NULL);
axis->name = NULL;
axis->size = 0;
axis->resolution = MS_WCS20_UNBOUNDED;
axis->scale = MS_WCS20_UNBOUNDED;
axis->resolutionUOM = NULL;
axis->subset = NULL;
return axis;
}
/************************************************************************/
/* msWCSFreeAxisObj20() */
/* */
/* Frees a wcs20AxisObj and releases all linked resources. */
/************************************************************************/
static void msWCSFreeAxisObj20(wcs20AxisObjPtr axis)
{
if(NULL == axis) {
return;
}
msFree(axis->name);
msFree(axis->resolutionUOM);
msWCSFreeSubsetObj20(axis->subset);
msFree(axis);
}
/************************************************************************/
/* msWCSFindAxis20() */
/* */
/* Helper function to retrieve an axis by the name from a params */
/* object. */
/************************************************************************/
static wcs20AxisObjPtr msWCSFindAxis20(wcs20ParamsObjPtr params,
const char *name)
{
int i = 0;
for(i = 0; i < params->numaxes; ++i) {
if(EQUAL(params->axes[i]->name, name)) {
return params->axes[i];
}
}
return NULL;
}
/************************************************************************/
/* msWCSInsertAxisObj20() */
/* */
/* Helper function to insert an axis object into the axes list of */
/* a params object. */
/************************************************************************/
static void msWCSInsertAxisObj20(wcs20ParamsObjPtr params, wcs20AxisObjPtr axis)
{
params->numaxes++;
params->axes = (wcs20AxisObjPtr*) msSmallRealloc(params->axes,
sizeof(wcs20AxisObjPtr) * (params->numaxes));
params->axes[params->numaxes - 1] = axis;
}
/************************************************************************/
/* msWCSCreateParamsObj20() */
/* */
/* Creates a new wcs20ParamsObj and initializes it to standard */
/* values. */
/************************************************************************/
wcs20ParamsObjPtr msWCSCreateParamsObj20()
{
wcs20ParamsObjPtr params
= (wcs20ParamsObjPtr) malloc(sizeof(wcs20ParamsObj));
MS_CHECK_ALLOC(params, sizeof(wcs20ParamsObj), NULL);
params->version = NULL;
params->request = NULL;
params->service = NULL;
params->accept_versions = NULL;
params->accept_languages = NULL;
params->sections = NULL;
params->updatesequence = NULL;
params->ids = NULL;
params->width = 0;
params->height = 0;
params->resolutionX = MS_WCS20_UNBOUNDED;
params->resolutionY = MS_WCS20_UNBOUNDED;
params->scale = MS_WCS20_UNBOUNDED;
params->scaleX = MS_WCS20_UNBOUNDED;
params->scaleY = MS_WCS20_UNBOUNDED;
params->resolutionUnits = NULL;
params->numaxes = 0;
params->axes = NULL;
params->format = NULL;
params->multipart = 0;
params->interpolation = NULL;
params->outputcrs = NULL;
params->subsetcrs = NULL;
params->bbox.minx = params->bbox.miny = -DBL_MAX;
params->bbox.maxx = params->bbox.maxy = DBL_MAX;
params->range_subset = NULL;
params->format_options = NULL;
return params;
}
/************************************************************************/
/* msWCSFreeParamsObj20() */
/* */
/* Frees a wcs20ParamsObj and releases all linked resources. */
/************************************************************************/
void msWCSFreeParamsObj20(wcs20ParamsObjPtr params)
{
if (NULL == params) {
return;
}
msFree(params->version);
msFree(params->request);
msFree(params->service);
CSLDestroy(params->accept_versions);
CSLDestroy(params->accept_languages);
CSLDestroy(params->sections);
msFree(params->updatesequence);
CSLDestroy(params->ids);
msFree(params->resolutionUnits);
msFree(params->format);
msFree(params->interpolation);
msFree(params->outputcrs);
msFree(params->subsetcrs);
while(params->numaxes > 0) {
params->numaxes -= 1;
msWCSFreeAxisObj20(params->axes[params->numaxes]);
}
msFree(params->axes);
CSLDestroy(params->range_subset);
CSLDestroy(params->format_options);
msFree(params);
}
/************************************************************************/
/* msWCSParseSubset20() */
/* */
/* Parses several string parameters and fills them into the */
/* subset object. */
/************************************************************************/
static int msWCSParseSubset20(wcs20SubsetObjPtr subset, const char *axis,
const char *crs, const char *min, const char *max)
{
int ts1, ts2;
ts1 = ts2 = MS_WCS20_UNDEFINED_VALUE;
if (subset == NULL) {
return MS_FAILURE;
}
if (axis == NULL || strlen(axis) == 0) {
msSetError(MS_WCSERR, "Subset axis is not given.",
"msWCSParseSubset20()");
return MS_FAILURE;
}
subset->axis = msStrdup(axis);
if (crs != NULL) {
subset->crs = msStrdup(crs);
}
/* Parse first (probably only) part of interval/point;
* check whether its a time value or a scalar value */
ts1 = msWCSParseTimeOrScalar20(&(subset->min), min);
if (ts1 == MS_WCS20_ERROR_VALUE) {
return MS_FAILURE;
}
/* check if its an interval */
/* if there is a comma, then it is */
if (max != NULL && strlen(max) > 0) {
subset->operation = MS_WCS20_TRIM;
/* Parse the second value of the interval */
ts2 = msWCSParseTimeOrScalar20(&(subset->max), max);
if (ts2 == MS_WCS20_ERROR_VALUE) {
return MS_FAILURE;
}
/* if at least one boundary is defined, use that value */
if ((ts1 == MS_WCS20_UNDEFINED_VALUE) ^ (ts2
== MS_WCS20_UNDEFINED_VALUE)) {
if (ts1 == MS_WCS20_UNDEFINED_VALUE) {
ts1 = ts2;
}
}
/* if time and scalar values do not fit, throw an error */
else if (ts1 != MS_WCS20_UNDEFINED_VALUE && ts2
!= MS_WCS20_UNDEFINED_VALUE && ts1 != ts2) {
msSetError(MS_WCSERR,
"Interval error: minimum is a %s value, maximum is a %s value",
"msWCSParseSubset20()", ts1 ? "time" : "scalar",
ts2 ? "time" : "scalar");
return MS_FAILURE;
}
/* if both min and max are unbounded -> throw an error */
if (subset->min.unbounded && subset->max.unbounded) {
msSetError(MS_WCSERR, "Invalid values: no bounds could be parsed",
"msWCSParseSubset20()");
return MS_FAILURE;
}
}
/* there is no second value, therefore it is a point.
* consequently set the operation to slice */
else {
subset->operation = MS_WCS20_SLICE;
if (ts1 == MS_WCS20_UNDEFINED_VALUE) {
msSetError(MS_WCSERR, "Invalid point value given",
"msWCSParseSubset20()");
return MS_FAILURE;
}
}
subset->timeOrScalar = ts1;
/* check whether the min is smaller than the max */
if (subset->operation == MS_WCS20_TRIM) {
if(subset->timeOrScalar == MS_WCS20_SCALAR_VALUE && subset->min.scalar == MS_WCS20_UNBOUNDED) {
subset->min.scalar = -MS_WCS20_UNBOUNDED;
}
if (subset->timeOrScalar == MS_WCS20_TIME_VALUE && subset->min.time
> subset->max.time) {
msSetError(MS_WCSERR,
"Minimum value of subset axis %s is larger than maximum value",
"msWCSParseSubset20()", subset->axis);
return MS_FAILURE;
}
if (subset->timeOrScalar == MS_WCS20_SCALAR_VALUE && subset->min.scalar > subset->max.scalar) {
msSetError(MS_WCSERR,
"Minimum value (%f) of subset axis '%s' is larger than maximum value (%f).",
"msWCSParseSubset20()", subset->min.scalar, subset->axis, subset->max.scalar);
return MS_FAILURE;
}
}
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSParseSubsetKVPString20() */
/* */
/* Creates a new wcs20SubsetObj, parses a string and fills */
/* the parsed values into the object. Returns NULL on failure. */
/* Subset string: axis [ , crs ] ( intervalOrPoint ) */
/************************************************************************/
static int msWCSParseSubsetKVPString20(wcs20SubsetObjPtr subset, char *string)
{
char *axis, *crs, *min, *max;
axis = string;
crs = NULL;
min = NULL;
max = NULL;
/* find first '(' */
min = strchr(string, '(');
/* if min could not be found, the string is invalid */
if (min == NULL) {
msSetError(MS_WCSERR, "Invalid axis subset string: '%s'",
"msWCSParseSubsetKVPString20()", string);
return MS_FAILURE;
}
/* set min to first letter */
*min = '\0';
++min;
/* cut the trailing ')' */
if (min[strlen(min) - 1] == ')') {
min[strlen(min) - 1] = '\0';
}
/* look if also a max is defined */
max = strchr(min, ',');
if (max != NULL) {
*max = '\0';
++max;
}
/* look if also a crs is defined */
crs = strchr(axis, ',');
if (crs != NULL) {
*crs = '\0';
++crs;
}
return msWCSParseSubset20(subset, axis, crs, min, max);
}
/************************************************************************/
/* msWCSParseSizeString20() */
/* */
/* Parses a string containing the axis and the size as an integer. */
/* Size string: axis ( size ) */
/************************************************************************/
static int msWCSParseSizeString20(char *string, char *outAxis, size_t axisStringLen, int *outSize)
{
char *number = NULL;
char *check = NULL;
/* find first '(', the character before the number */
number = strchr(string, '(');
if(NULL == number) {
msSetError(MS_WCSERR, "Invalid size parameter value.",
"msWCSParseSize20()");
return MS_FAILURE;
}
/* cut trailing ')' */
check = strchr(string, ')');
if(NULL == check) {
msSetError(MS_WCSERR, "Invalid size parameter value.",
"msWCSParseSize20()");
return MS_FAILURE;
}
*number = '\0';
++number;
*check = '\0';
strlcpy(outAxis, string, axisStringLen);
/* parse size value */
if(msStringParseInteger(number, outSize) != MS_SUCCESS) {
msSetError(MS_WCSERR, "Parameter value '%s' is not a valid integer.",
"msWCSParseSize20()", number);
return MS_FAILURE;
}
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSParseResolutionString20() */
/* */
/* Parses a resolution string and returns the axis, the units of */
/* measure and the resolution value. */
/* Subset string: axis ( value ) */
/************************************************************************/
static int msWCSParseResolutionString20(char *string,
char *outAxis, size_t axisStringLen, double *outResolution)
{
char *number = NULL;
char *check = NULL;
/* find brackets */
number = strchr(string, '(');
if(NULL == number) {
msSetError(MS_WCSERR, "Invalid resolution parameter value : %s.",
"msWCSParseSize20()", string);
return MS_FAILURE;
}
/* cut trailing ')' */
check = strchr(string, ')');
if(NULL == check) {
msSetError(MS_WCSERR, "Invalid size parameter value.",
"msWCSParseSize20()");
return MS_FAILURE;
}
*number = '\0';
++number;
*check = '\0';
strlcpy(outAxis, string, axisStringLen);
if(msStringParseDouble(number, outResolution) != MS_SUCCESS) {
*outResolution = MS_WCS20_UNBOUNDED;
msSetError(MS_WCSERR, "Invalid resolution parameter value : %s.",
"msWCSParseSize20()", number);
return MS_FAILURE;
}
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSParseScaleString20() */
/* */
/* Parses a scale string and returns the axis, the and the value. */
/* Subset string: axis ( value ) */
/************************************************************************/
static int msWCSParseScaleString20(char *string,
char *outAxis, size_t axisStringLen, double *outScale)
{
char *number = NULL;
char *check = NULL;
/* find brackets */
number = strchr(string, '(');
if(NULL == number) {
msSetError(MS_WCSERR, "Invalid resolution parameter value : %s.",
"msWCSParseScaleString20()", string);
return MS_FAILURE;
}
/* cut trailing ')' */
check = strchr(string, ')');
if(NULL == check || check < number) {
msSetError(MS_WCSERR, "Invalid scale parameter value.",
"msWCSParseScaleString20()");
return MS_FAILURE;
}
*number = '\0';
++number;
*check = '\0';
strlcpy(outAxis, string, axisStringLen);
if(msStringParseDouble(number, outScale) != MS_SUCCESS || *outScale <= 0.0) {
*outScale = MS_WCS20_UNBOUNDED;
msSetError(MS_WCSERR, "Invalid scale parameter value : %s.",
"msWCSParseScaleString20()", number);
return MS_FAILURE;
}
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSParseResolutionString20() */
/* */
/* Parses a resolution string and returns the axis, the units of */
/* measure and the resolution value. */
/* Subset string: axis ( value ) */
/************************************************************************/
static int msWCSParseScaleExtentString20(char *string, char *outAxis,
size_t axisStringLen,
int *outMin, int *outMax)
{
char *number = NULL;
char *check = NULL;
char *colon = NULL;
/* find brackets */
number = strchr(string, '(');
if(NULL == number) {
msSetError(MS_WCSERR, "Invalid extent parameter value : %s.",
"msWCSParseScaleExtentString20()", string);
return MS_FAILURE;
}
/* find colon */
colon = strchr(string, ':');
if(NULL == colon || colon < number) {
msSetError(MS_WCSERR, "Invalid extent parameter value : %s.",
"msWCSParseScaleExtentString20()", string);
return MS_FAILURE;
}
/* cut trailing ')' */
check = strchr(string, ')');
if(NULL == check || check < colon) {
msSetError(MS_WCSERR, "Invalid extent parameter value.",
"msWCSParseScaleExtentString20()");
return MS_FAILURE;
}
*number = '\0';
++number;
*colon = '\0';
++colon;
*check = '\0';
strlcpy(outAxis, string, axisStringLen);
if(msStringParseInteger(number, outMin) != MS_SUCCESS) {
*outMin = 0;
msSetError(MS_WCSERR, "Invalid min parameter value : %s.",
"msWCSParseScaleExtentString20()", number);
return MS_FAILURE;
}
else if(msStringParseInteger(colon, outMax) != MS_SUCCESS) {
*outMax = 0;
msSetError(MS_WCSERR, "Invalid resolution parameter value : %s.",
"msWCSParseScaleExtentString20()", colon);
return MS_FAILURE;
}
if (*outMin > *outMax) {
msSetError(MS_WCSERR, "Invalid extent: lower part is higher than upper part.",
"msWCSParseScaleExtentString20()");
return MS_FAILURE;
}
return MS_SUCCESS;
}
#if defined(USE_LIBXML2)
/*
Utility function to get the first child of a node with a given node name
*/
xmlNodePtr msLibXml2GetFirstChild(xmlNodePtr parent, const char *name) {
xmlNodePtr node;
if (!parent || !name) {
return NULL;
}
XML_FOREACH_CHILD(parent, node) {
XML_LOOP_IGNORE_COMMENT_OR_TEXT(node);
if (EQUAL((char *)node->name, name)) {
return node;
}
}
return NULL;
}
/*
Utility function to get the first child of a node with a given node name and
namespace.
*/
xmlNodePtr msLibXml2GetFirstChildNs(xmlNodePtr parent, const char *name, xmlNsPtr ns) {
xmlNodePtr node;
if (!parent || !name || !ns) {
return NULL;
}
XML_FOREACH_CHILD(parent, node) {
XML_LOOP_IGNORE_COMMENT_OR_TEXT(node);
if (EQUAL((char *)node->name, name) && ns == node->ns) {
return node;
}
}
return NULL;
}
/*
Utility function to get the first child of a node with a given node name
*/
xmlNodePtr msLibXml2GetFirstChildElement(xmlNodePtr parent) {
xmlNodePtr node;
if (!parent) {
return NULL;
}
XML_FOREACH_CHILD(parent, node) {
if (node->type == XML_ELEMENT_NODE) {
return node;
}
}
return NULL;
}
#endif /* defined(USE_LIBXML2) */
/************************************************************************/
/* msWCSParseRequest20_XMLGetCapabilities() */
/* */
/* Parses a DOM element, representing a GetCapabilities-request */
/* to a params object. */
/************************************************************************/
#if defined(USE_LIBXML2)
static int msWCSParseRequest20_XMLGetCapabilities(
xmlNodePtr root, wcs20ParamsObjPtr params)
{
xmlNodePtr child;
char *content = NULL;
XML_FOREACH_CHILD(root, child) {
XML_LOOP_IGNORE_COMMENT_OR_TEXT(child)
else if (EQUAL((char *)child->name, "AcceptVersions")) {
xmlNodePtr versionNode = NULL;
XML_FOREACH_CHILD(child, versionNode) {
XML_LOOP_IGNORE_COMMENT_OR_TEXT(versionNode);
XML_ASSERT_NODE_NAME(versionNode, "Version");
content = (char *)xmlNodeGetContent(versionNode);
params->accept_versions = CSLAddString(params->accept_versions, content);
xmlFree(content);
}
} else if(EQUAL((char *)child->name, "Sections")) {
xmlNodePtr sectionNode = NULL;
XML_FOREACH_CHILD(child, sectionNode) {
XML_LOOP_IGNORE_COMMENT_OR_TEXT(sectionNode)
XML_ASSERT_NODE_NAME(sectionNode, "Section");
content = (char *)xmlNodeGetContent(sectionNode);
params->sections = CSLAddString(params->sections, content);
xmlFree(content);
}
} else if(EQUAL((char *)child->name, "UpdateSequence")) {
params->updatesequence =
(char *)xmlNodeGetContent(child);
} else if(EQUAL((char *)child->name, "AcceptFormats")) {
/* Maybe not necessary, since only format is xml. */
/* At least ignore it, to not generate an error. */
} else if(EQUAL((char *)child->name, "AcceptLanguages")) {
xmlNodePtr languageNode;
XML_FOREACH_CHILD(child, languageNode) {
XML_LOOP_IGNORE_COMMENT_OR_TEXT(languageNode)
XML_ASSERT_NODE_NAME(languageNode, "Language");
content = (char *)xmlNodeGetContent(languageNode);
params->accept_languages = CSLAddString(params->accept_languages, content);
xmlFree(content);
}
} else {
XML_UNKNOWN_NODE_ERROR(child);
}
}
return MS_SUCCESS;
}
#endif
/************************************************************************/
/* msWCSParseRequest20_XMLDescribeCoverage() */
/* */
/* Parses a DOM element, representing a DescribeCoverage-request */
/* to a params object. */
/************************************************************************/
#if defined(USE_LIBXML2)
static int msWCSParseRequest20_XMLDescribeCoverage(
xmlNodePtr root, wcs20ParamsObjPtr params)
{
xmlNodePtr child;
int numIds = 0;
char *id;
XML_FOREACH_CHILD(root, child) {
XML_LOOP_IGNORE_COMMENT_OR_TEXT(child)
XML_ASSERT_NODE_NAME(child, "CoverageID");
/* Node content is the coverage ID */
id = (char *)xmlNodeGetContent(child);
if (id == NULL || strlen(id) == 0) {
msSetError(MS_WCSERR, "CoverageID could not be parsed.",
"msWCSParseRequest20_XMLDescribeCoverage()");
return MS_FAILURE;
}
/* insert coverage ID into the list */
++numIds;
params->ids = CSLAddString(params->ids, (char *)id);
xmlFree(id);
}
return MS_SUCCESS;
}
#endif
/************************************************************************/
/* msWCSParseRequest20_XMLGetCoverage() */
/* */
/* Parses a DOM element, representing a GetCoverage-request to a */
/* params object. */
/************************************************************************/
#if defined(USE_LIBXML2)
static int msWCSParseRequest20_XMLGetCoverage(
mapObj* map, xmlNodePtr root, wcs20ParamsObjPtr params)
{
xmlNodePtr child;
int numIds = 0;
char *id;
XML_FOREACH_CHILD(root, child) {
XML_LOOP_IGNORE_COMMENT_OR_TEXT(child)
else if (EQUAL((char *)child->name, "CoverageID")) {
/* Node content is the coverage ID */
id = (char *)xmlNodeGetContent(child);
if (id == NULL || strlen(id) == 0) {
msSetError(MS_WCSERR, "CoverageID could not be parsed.",
"msWCSParseRequest20_XMLGetCoverage()");
return MS_FAILURE;
}
/* insert coverage ID into the list */
++numIds;
params->ids = CSLAddString(params->ids, (char *)id);
xmlFree(id);
} else if (EQUAL((char *) child->name, "Format")) {
msFree(params->format);
params->format = (char *)xmlNodeGetContent(child);
} else if (EQUAL((char *) child->name, "Mediatype")) {
char *content = (char *)xmlNodeGetContent(child);
if(content != NULL && (EQUAL(content, "multipart/mixed")
|| EQUAL(content, "multipart/related"))) {
params->multipart = MS_TRUE;
}
else {
msSetError(MS_WCSERR, "Invalid value '%s' for parameter 'Mediatype'.",
"msWCSParseRequest20()", content);
xmlFree(content);
return MS_FAILURE;
}
xmlFree(content);
} else if (EQUAL((char *) child->name, "DimensionTrim")) {
wcs20AxisObjPtr axis = NULL;
wcs20SubsetObjPtr subset = NULL;
xmlNodePtr node = NULL;
char *axisName = NULL, *min = NULL, *max = NULL, *crs = NULL;
/* get strings for axis, min and max */
XML_FOREACH_CHILD(child, node) {
XML_LOOP_IGNORE_COMMENT_OR_TEXT(node)
else if (EQUAL((char *)node->name, "Dimension")) {
if (axisName != NULL) {
msSetError(MS_WCSERR,
"Parameter 'Dimension' is already set.",
"msWCSParseRequest20_XMLGetCoverage()");
return MS_FAILURE;
}
axisName = (char *) xmlNodeGetContent(node);
crs = (char *) xmlGetProp(node, BAD_CAST "crs");
} else if (EQUAL((char *)node->name, "trimLow")) {
min = (char *) xmlNodeGetContent(node);
} else if (EQUAL((char *)node->name, "trimHigh")) {
max = (char *) xmlNodeGetContent(node);
} else {
msFree(axisName);
msFree(min);
msFree(max);
msFree(crs);
XML_UNKNOWN_NODE_ERROR(node);
}
}
if(NULL == (subset = msWCSCreateSubsetObj20())) {
msFree(axisName);
msFree(min);
msFree(max);
msFree(crs);
return MS_FAILURE;
}
/* min and max have to have a value */
if(min == NULL ) {
min = msStrdup("*");
}
if(max == NULL) {
max = msStrdup("*");
}
if (msWCSParseSubset20(subset, axisName, crs, min, max)
== MS_FAILURE) {
msWCSFreeSubsetObj20(subset);
msWCSException(map, "InvalidSubsetting", "subset", "2.0.1");
return MS_DONE;
}
if(NULL == (axis = msWCSFindAxis20(params, subset->axis))) {
if(NULL == (axis = msWCSCreateAxisObj20())) {
msFree(axisName);
msFree(min);
msFree(max);
msFree(crs);
return MS_FAILURE;
}
axis->name = msStrdup(subset->axis);
msWCSInsertAxisObj20(params, axis);
}
axis->subset = subset;
/* cleanup */
msFree(axisName);
msFree(min);