1 : /******************************************************************************
2 : * $Id: wmsdriver.cpp 18020 2009-11-14 14:33:20Z rouault $
3 : *
4 : * Project: WMS Client Driver
5 : * Purpose: Implementation of Dataset and RasterBand classes for WMS
6 : * and other similar services.
7 : * Author: Adam Nowacki, nowak@xpam.de
8 : *
9 : ******************************************************************************
10 : * Copyright (c) 2007, Adam Nowacki
11 : *
12 : * Permission is hereby granted, free of charge, to any person obtaining a
13 : * copy of this software and associated documentation files (the "Software"),
14 : * to deal in the Software without restriction, including without limitation
15 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 : * and/or sell copies of the Software, and to permit persons to whom the
17 : * Software is furnished to do so, subject to the following conditions:
18 : *
19 : * The above copyright notice and this permission notice shall be included
20 : * in all copies or substantial portions of the Software.
21 : *
22 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 : * DEALINGS IN THE SOFTWARE.
29 : ****************************************************************************/
30 :
31 : #include "stdinc.h"
32 :
33 8889 : GDALDataset *GDALWMSDatasetOpen(GDALOpenInfo *poOpenInfo) {
34 8889 : CPLXMLNode *config = NULL;
35 8889 : CPLErr ret = CE_None;
36 :
37 8893 : if ((poOpenInfo->nHeaderBytes == 0) && EQUALN((const char *) poOpenInfo->pszFilename, "<GDAL_WMS>", 10)) {
38 4 : config = CPLParseXMLString(poOpenInfo->pszFilename);
39 8886 : } else if ((poOpenInfo->nHeaderBytes >= 10) && EQUALN((const char *) poOpenInfo->pabyHeader, "<GDAL_WMS>", 10)) {
40 1 : config = CPLParseXMLFile(poOpenInfo->pszFilename);
41 8884 : } else return NULL;
42 5 : if (config == NULL) return NULL;
43 :
44 : /* -------------------------------------------------------------------- */
45 : /* Confirm the requested access is supported. */
46 : /* -------------------------------------------------------------------- */
47 5 : if( poOpenInfo->eAccess == GA_Update )
48 : {
49 0 : CPLDestroyXMLNode(config);
50 : CPLError( CE_Failure, CPLE_NotSupported,
51 : "The WMS driver does not support update access to existing"
52 0 : " datasets.\n" );
53 0 : return NULL;
54 : }
55 :
56 5 : GDALWMSDataset *ds = new GDALWMSDataset();
57 5 : ret = ds->Initialize(config);
58 5 : if (ret != CE_None) {
59 0 : delete ds;
60 0 : ds = 0;
61 : }
62 5 : CPLDestroyXMLNode(config);
63 :
64 5 : return ds;
65 : }
66 :
67 : /************************************************************************/
68 : /* GDALDeregister_WMS() */
69 : /************************************************************************/
70 :
71 325 : static void GDALDeregister_WMS( GDALDriver * )
72 :
73 : {
74 325 : DestroyWMSMiniDriverManager();
75 325 : }
76 :
77 : /************************************************************************/
78 : /* GDALRegister_WMS() */
79 : /************************************************************************/
80 :
81 338 : void GDALRegister_WMS() {
82 : GDALDriver *driver;
83 338 : if (GDALGetDriverByName("WMS") == NULL) {
84 336 : driver = new GDALDriver();
85 336 : driver->SetDescription("WMS");
86 336 : driver->SetMetadataItem(GDAL_DMD_LONGNAME, "OGC Web Map Service");
87 336 : driver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "frmt_wms.html");
88 336 : driver->pfnOpen = GDALWMSDatasetOpen;
89 336 : driver->pfnUnloadDriver = GDALDeregister_WMS;
90 336 : GetGDALDriverManager()->RegisterDriver(driver);
91 :
92 336 : GDALWMSMiniDriverManager *const mdm = GetGDALWMSMiniDriverManager();
93 672 : mdm->Register(new GDALWMSMiniDriverFactory_WMS());
94 672 : mdm->Register(new GDALWMSMiniDriverFactory_TileService());
95 672 : mdm->Register(new GDALWMSMiniDriverFactory_WorldWind());
96 672 : mdm->Register(new GDALWMSMiniDriverFactory_TMS());
97 : }
98 338 : }
|