正在显示
19 个修改的文件
包含
1243 行增加
和
320 行删除
@@ -12,21 +12,21 @@ | @@ -12,21 +12,21 @@ | ||
12 | #include "dmpproviderregistry.h" | 12 | #include "dmpproviderregistry.h" |
13 | #include "libpq-fe.h" | 13 | #include "libpq-fe.h" |
14 | #include "clsUtil.h" | 14 | #include "clsUtil.h" |
15 | +#include <boost/algorithm/string/predicate.hpp> | ||
15 | 16 | ||
16 | DmpVectorLayer::DmpVectorLayer(const std::string &path, | 17 | DmpVectorLayer::DmpVectorLayer(const std::string &path, |
17 | - const std::string &baseName, | ||
18 | - const std::string &providerKey, | ||
19 | - const DmpVectorLayer::LayerOptions &options) | ||
20 | - : DmpMapLayer(DmpMapLayerType::VectorLayer, baseName, path) | ||
21 | - , readExtentFromXml_(options.readExtentFromXml) | 18 | + const std::string &baseName, |
19 | + const std::string &providerKey, | ||
20 | + const DmpVectorLayer::LayerOptions &options) | ||
21 | + : DmpMapLayer(DmpMapLayerType::VectorLayer, baseName, path), readExtentFromXml_(options.readExtentFromXml) | ||
22 | { | 22 | { |
23 | - wkbType_ = options.fallbackWkbType; | ||
24 | - setProviderType(providerKey); | 23 | + wkbType_ = options.fallbackWkbType; |
24 | + setProviderType(providerKey); | ||
25 | 25 | ||
26 | - if (!path.empty() && !providerKey.empty()) | ||
27 | - { | ||
28 | - setDataSource(path, baseName, providerKey, options.loadDefaultStyle ); | ||
29 | - } | 26 | + if (!path.empty() && !providerKey.empty()) |
27 | + { | ||
28 | + setDataSource(path, baseName, providerKey, options.loadDefaultStyle); | ||
29 | + } | ||
30 | } | 30 | } |
31 | 31 | ||
32 | DmpVectorLayer::~DmpVectorLayer() | 32 | DmpVectorLayer::~DmpVectorLayer() |
@@ -35,221 +35,254 @@ DmpVectorLayer::~DmpVectorLayer() | @@ -35,221 +35,254 @@ DmpVectorLayer::~DmpVectorLayer() | ||
35 | 35 | ||
36 | DmpMapLayerRenderer *DmpVectorLayer::createMapRenderer(DmpRenderContext &rendererContext) | 36 | DmpMapLayerRenderer *DmpVectorLayer::createMapRenderer(DmpRenderContext &rendererContext) |
37 | { | 37 | { |
38 | - return new DmpVectorLayerRenderer(this, rendererContext); | 38 | + return new DmpVectorLayerRenderer(this, rendererContext); |
39 | } | 39 | } |
40 | 40 | ||
41 | bool DmpVectorLayer::readXml(const boost::property_tree::ptree &layerNode) | 41 | bool DmpVectorLayer::readXml(const boost::property_tree::ptree &layerNode) |
42 | { | 42 | { |
43 | - //id="gzxxd_aabe200b_5b63_4b82_8546_af1fc99e4ec6" name="gzxxd" alias="中学" type="1" | ||
44 | - // geometry="Point" alwaysShow="true" maxScale="0" maxScale="50000" | ||
45 | - id_ = layerNode.get<std::string>("<xmlattr>.id"); | ||
46 | - name_ = layerNode.get<std::string>("<xmlattr>.name"); | ||
47 | - title_ = layerNode.get<std::string>("<xmlattr>.alias"); | ||
48 | - boost::property_tree::ptree pExtent = layerNode.get_child("extent"); | ||
49 | - extent_ = DmpXmlUtils::readRectangle(pExtent); | ||
50 | - dataSource_ = layerNode.get<std::string>("datasource"); | ||
51 | - | ||
52 | - //setDataProvider("postgres"); | ||
53 | - // boost::property_tree::ptree pResourceMetadata = layerNode.get_child("resourcemetadata"); | ||
54 | - // schema_ = layerNode.get<std::string>("schema"); | ||
55 | - // geom_ = layerNode.get<std::string>("geom"); | ||
56 | - // featurecount_ = layerNode.get<unsigned int>("featurecount"); | ||
57 | - | ||
58 | - boost::property_tree::ptree ptRenderer = layerNode.get_child("renderer"); | ||
59 | - auto pIter = ptRenderer.begin(); | ||
60 | - if(pIter == ptRenderer.end())return false; | ||
61 | - DmapCore_30::Renderer* renderer_30 = nullptr; | ||
62 | - DmapCore_30::clsXML::XMLParse(pIter->first, pIter->second, &renderer_30); | ||
63 | - renderer_30_ = shared_ptr<DmapCore_30::Renderer>(renderer_30); | ||
64 | - | ||
65 | - // geom_ = "geom"; | ||
66 | - // schema_ = "public"; | ||
67 | - // wkbType_ = DmpWkbTypes::MultiLineString; | ||
68 | - | ||
69 | - return true; | 43 | + //id="gzxxd_aabe200b_5b63_4b82_8546_af1fc99e4ec6" name="gzxxd" alias="中学" type="1" |
44 | + // geometry="Point" alwaysShow="true" maxScale="0" maxScale="50000" | ||
45 | + id_ = layerNode.get<std::string>("<xmlattr>.id"); | ||
46 | + name_ = layerNode.get<std::string>("<xmlattr>.name"); | ||
47 | + title_ = layerNode.get<std::string>("<xmlattr>.alias"); | ||
48 | + boost::property_tree::ptree pExtent = layerNode.get_child("extent"); | ||
49 | + extent_ = DmpXmlUtils::readRectangle(pExtent); | ||
50 | + dataSource_ = layerNode.get<std::string>("datasource"); | ||
51 | + | ||
52 | + if (!setDataProvider(dataSource_)) | ||
53 | + { | ||
54 | + schema_ = layerNode.get<std::string>("<xmlattr>.schema"); | ||
55 | + geom_ = layerNode.get<std::string>("<xmlattr>.geomfield"); | ||
56 | + wkbTypeString_ = layerNode.get<std::string>("<xmlattr>.geometry"); | ||
57 | + featurecount_ = layerNode.get<unsigned int>("<xmlattr>.featurecount"); | ||
58 | + srid_ = layerNode.get<std::string>("<xmlattr>.srid"); | ||
59 | + } | ||
60 | + | ||
61 | + if (boost::iequals(wkbTypeString_, "POINT")) | ||
62 | + wkbType_ = DmpWkbTypes::Point; | ||
63 | + else if (boost::iequals(wkbTypeString_, "MULTIPOINT")) | ||
64 | + wkbType_ = DmpWkbTypes::MultiPoint; | ||
65 | + else if (boost::iequals(wkbTypeString_, "LINESTRING")) | ||
66 | + wkbType_ = DmpWkbTypes::LineString; | ||
67 | + else if (boost::iequals(wkbTypeString_, "MULTILINESTRING")) | ||
68 | + wkbType_ = DmpWkbTypes::MultiLineString; | ||
69 | + else if (boost::iequals(wkbTypeString_, "POLYGON")) | ||
70 | + wkbType_ = DmpWkbTypes::Polygon; | ||
71 | + else if (boost::iequals(wkbTypeString_, "MULTIPOLYGON")) | ||
72 | + wkbType_ = DmpWkbTypes::MultiPolygon; | ||
73 | + else if (boost::iequals(wkbTypeString_, "GEOMETRY")) | ||
74 | + wkbType_ = DmpWkbTypes::Unknown; | ||
75 | + | ||
76 | + boost::property_tree::ptree ptRenderer = layerNode.get_child("renderer"); | ||
77 | + auto pIter = ptRenderer.begin(); | ||
78 | + if (pIter == ptRenderer.end()) | ||
79 | + return false; | ||
80 | + DmapCore_30::Renderer *renderer_30 = nullptr; | ||
81 | + DmapCore_30::clsXML::XMLParse(pIter->first, pIter->second, &renderer_30); | ||
82 | + renderer_30_ = shared_ptr<DmapCore_30::Renderer>(renderer_30); | ||
83 | + | ||
84 | + // geom_ = "geom"; | ||
85 | + // schema_ = "public"; | ||
86 | + // wkbType_ = DmpWkbTypes::MultiLineString; | ||
87 | + | ||
88 | + return true; | ||
70 | } | 89 | } |
71 | 90 | ||
72 | bool DmpVectorLayer::writeXml(boost::property_tree::ptree &layerNode) | 91 | bool DmpVectorLayer::writeXml(boost::property_tree::ptree &layerNode) |
73 | { | 92 | { |
74 | - layerNode.add("<xmlattr>.id", id_); | ||
75 | - layerNode.add("<xmlattr>.name", name_); | ||
76 | - layerNode.add("<xmlattr>.alias", title_); | ||
77 | - | ||
78 | - | ||
79 | - boost::property_tree::ptree ptExtent; | ||
80 | - ptExtent.add("xmin", extent_.xmin()); | ||
81 | - ptExtent.add("ymin", extent_.ymin()); | ||
82 | - ptExtent.add("xmax", extent_.xmax()); | ||
83 | - ptExtent.add("ymax", extent_.ymax()); | ||
84 | - layerNode.add_child("extent", ptExtent); | ||
85 | - | ||
86 | - layerNode.add("datasource", dataSource_); | ||
87 | - boost::property_tree::ptree ptRenderer; | ||
88 | - if(this->renderer_30_) | ||
89 | - { | ||
90 | - this->renderer_30_->ParsePtree(ptRenderer); | ||
91 | - } | ||
92 | - layerNode.add_child("renderer",ptRenderer); | ||
93 | - | ||
94 | - return true; | 93 | + layerNode.add("<xmlattr>.id", id_); |
94 | + layerNode.add("<xmlattr>.name", name_); | ||
95 | + layerNode.add("<xmlattr>.alias", title_); | ||
96 | + | ||
97 | + boost::property_tree::ptree ptExtent; | ||
98 | + ptExtent.add("xmin", extent_.xmin()); | ||
99 | + ptExtent.add("ymin", extent_.ymin()); | ||
100 | + ptExtent.add("xmax", extent_.xmax()); | ||
101 | + ptExtent.add("ymax", extent_.ymax()); | ||
102 | + layerNode.add_child("extent", ptExtent); | ||
103 | + | ||
104 | + layerNode.add("datasource", dataSource_); | ||
105 | + boost::property_tree::ptree ptRenderer; | ||
106 | + if (this->renderer_30_) | ||
107 | + { | ||
108 | + this->renderer_30_->ParsePtree(ptRenderer); | ||
109 | + } | ||
110 | + layerNode.add_child("renderer", ptRenderer); | ||
111 | + | ||
112 | + return true; | ||
95 | } | 113 | } |
96 | 114 | ||
97 | -bool DmpVectorLayer::writejson(std::string& json) | 115 | +bool DmpVectorLayer::writejson(std::string &json) |
98 | { | 116 | { |
99 | - string shapeTypeString ="UNKNOWORD"; | 117 | + string shapeTypeString = "UNKNOWORD"; |
100 | 118 | ||
101 | - switch (wkbType_) | ||
102 | - { | ||
103 | - case DmpWkbTypes::Point: shapeTypeString = "POINT"; | ||
104 | - break; | ||
105 | - case DmpWkbTypes::MultiPoint: shapeTypeString = "MULTIPOINT"; | ||
106 | - break; | ||
107 | - case DmpWkbTypes::LineString: shapeTypeString = "LINESTRING"; | ||
108 | - break; | ||
109 | - case DmpWkbTypes::MultiLineString: shapeTypeString = "MULTILINESTRING"; | ||
110 | - break; | ||
111 | - case DmpWkbTypes::Polygon : shapeTypeString = "POLYGON"; | ||
112 | - break; | ||
113 | - case DmpWkbTypes::MultiPolygon : shapeTypeString = "MULTIPOLYGON"; | ||
114 | - break; | ||
115 | - default: | ||
116 | - shapeTypeString ="UNKNOWORD"; | ||
117 | - break; | ||
118 | - } | ||
119 | - | ||
120 | - bool alwaysShow = this->minScale() == 0 && this->maxScale() >10000000000; | ||
121 | - char buff_maxscale[100]; | ||
122 | - char buff_minscale[100]; | ||
123 | - if(this->maxScale() > 100000000) | ||
124 | - { | ||
125 | - sprintf(buff_maxscale,"%e", this->maxScale()); | ||
126 | - } | ||
127 | - else | ||
128 | - { | ||
129 | - sprintf(buff_maxscale,"%.0f", this->maxScale()); | ||
130 | - } | ||
131 | - | ||
132 | - if(this->minScale() > 100000000) | ||
133 | - { | ||
134 | - sprintf(buff_minscale,"%e", this->minScale() ); | ||
135 | - } | ||
136 | - else | ||
137 | - { | ||
138 | - sprintf(buff_minscale,"%.0f", this->minScale() ); | ||
139 | - } | ||
140 | - //Display scale setting type="1" geometry="Point" alwaysShow="true" maxScale="0" maxScale="50000"> | ||
141 | - char resultbuff[1000]; | ||
142 | - string json_source = this->source(); | ||
143 | - DmapCore_30::clsUtil::ToJSONString(json_source); | ||
144 | - sprintf(resultbuff, | ||
145 | - R"({"workspace":"","type":"1","dbsource":"%s","data":"","schema":"%s","alias":"%s","name":"%s","id":"%s","filter":"%s","visible":"%s","tag":"","minScale":"%s","maxScale":"%s","geometry":"%s","alwaysShow":"%s")", | ||
146 | - json_source.c_str(), | ||
147 | - this->schema().c_str(), | ||
148 | - this->title().c_str(), | ||
149 | - this->name().c_str(), | ||
150 | - this->id().c_str(), | ||
151 | - this->wherestr_.c_str(), | ||
152 | - "true", | ||
153 | - buff_minscale,buff_maxscale, | ||
154 | - shapeTypeString.c_str(), | ||
155 | - alwaysShow?"true":"false" | ||
156 | - ); | ||
157 | - | ||
158 | - json.append(resultbuff); | ||
159 | - if(this->renderer_30_ != nullptr) | ||
160 | - { | ||
161 | - | ||
162 | - json.append(","); | ||
163 | - DmapCore_30::AppendBuffer ab; | ||
164 | - this->renderer_30_->ToJson(&ab); | ||
165 | - json.append(ab.GetString()); | ||
166 | - } | ||
167 | - json.append("}"); | ||
168 | - return true; | 119 | + switch (wkbType_) |
120 | + { | ||
121 | + case DmpWkbTypes::Point: | ||
122 | + shapeTypeString = "POINT"; | ||
123 | + break; | ||
124 | + case DmpWkbTypes::MultiPoint: | ||
125 | + shapeTypeString = "MULTIPOINT"; | ||
126 | + break; | ||
127 | + case DmpWkbTypes::LineString: | ||
128 | + shapeTypeString = "LINESTRING"; | ||
129 | + break; | ||
130 | + case DmpWkbTypes::MultiLineString: | ||
131 | + shapeTypeString = "MULTILINESTRING"; | ||
132 | + break; | ||
133 | + case DmpWkbTypes::Polygon: | ||
134 | + shapeTypeString = "POLYGON"; | ||
135 | + break; | ||
136 | + case DmpWkbTypes::MultiPolygon: | ||
137 | + shapeTypeString = "MULTIPOLYGON"; | ||
138 | + break; | ||
139 | + default: | ||
140 | + shapeTypeString = "UNKNOWORD"; | ||
141 | + break; | ||
142 | + } | ||
143 | + | ||
144 | + bool alwaysShow = this->minScale() == 0 && this->maxScale() > 10000000000; | ||
145 | + char buff_maxscale[100]; | ||
146 | + char buff_minscale[100]; | ||
147 | + if (this->maxScale() > 100000000) | ||
148 | + { | ||
149 | + sprintf(buff_maxscale, "%e", this->maxScale()); | ||
150 | + } | ||
151 | + else | ||
152 | + { | ||
153 | + sprintf(buff_maxscale, "%.0f", this->maxScale()); | ||
154 | + } | ||
155 | + | ||
156 | + if (this->minScale() > 100000000) | ||
157 | + { | ||
158 | + sprintf(buff_minscale, "%e", this->minScale()); | ||
159 | + } | ||
160 | + else | ||
161 | + { | ||
162 | + sprintf(buff_minscale, "%.0f", this->minScale()); | ||
163 | + } | ||
164 | + //Display scale setting type="1" geometry="Point" alwaysShow="true" maxScale="0" maxScale="50000"> | ||
165 | + char resultbuff[1000]; | ||
166 | + string json_source = this->source(); | ||
167 | + DmapCore_30::clsUtil::ToJSONString(json_source); | ||
168 | + sprintf(resultbuff, | ||
169 | + R"({"workspace":"","type":"1","dbsource":"%s","data":"","schema":"%s","alias":"%s","name":"%s","id":"%s","filter":"%s","visible":"%s","tag":"","minScale":"%s","maxScale":"%s","geometry":"%s","alwaysShow":"%s")", | ||
170 | + json_source.c_str(), | ||
171 | + this->schema().c_str(), | ||
172 | + this->title().c_str(), | ||
173 | + this->name().c_str(), | ||
174 | + this->id().c_str(), | ||
175 | + this->wherestr_.c_str(), | ||
176 | + "true", | ||
177 | + buff_minscale, buff_maxscale, | ||
178 | + shapeTypeString.c_str(), | ||
179 | + alwaysShow ? "true" : "false"); | ||
180 | + | ||
181 | + json.append(resultbuff); | ||
182 | + if (this->renderer_30_ != nullptr) | ||
183 | + { | ||
184 | + | ||
185 | + json.append(","); | ||
186 | + DmapCore_30::AppendBuffer ab; | ||
187 | + this->renderer_30_->ToJson(&ab); | ||
188 | + json.append(ab.GetString()); | ||
189 | + } | ||
190 | + json.append("}"); | ||
191 | + return true; | ||
169 | } | 192 | } |
170 | 193 | ||
171 | void DmpVectorLayer::setRenderer(DmpFeatureRenderer *renderer) | 194 | void DmpVectorLayer::setRenderer(DmpFeatureRenderer *renderer) |
172 | { | 195 | { |
173 | - | ||
174 | } | 196 | } |
175 | 197 | ||
176 | void DmpVectorLayer::setDataSource(const std::string &dataSource, const std::string &baseName, const std::string &provider, bool loadDefaultStyleFlag) | 198 | void DmpVectorLayer::setDataSource(const std::string &dataSource, const std::string &baseName, const std::string &provider, bool loadDefaultStyleFlag) |
177 | { | 199 | { |
178 | - DmpWkbTypes::GeometryType geomType = GeometryType(); | 200 | + DmpWkbTypes::GeometryType geomType = GeometryType(); |
179 | } | 201 | } |
180 | 202 | ||
181 | DmpWkbTypes::GeometryType DmpVectorLayer::GeometryType() const | 203 | DmpWkbTypes::GeometryType DmpVectorLayer::GeometryType() const |
182 | { | 204 | { |
183 | - return DmpWkbTypes::GeometryType(wkbType_); | 205 | + return DmpWkbTypes::GeometryType(wkbType_); |
184 | } | 206 | } |
185 | 207 | ||
186 | -bool DmpVectorLayer::setDataProvider(std::string const &provider) | 208 | +bool DmpVectorLayer::setDataProvider(const std::string &provider) |
187 | { | 209 | { |
188 | - isinit_ = true; | ||
189 | - //临时测试使用 | ||
190 | - PGconn* pPGconn = PQconnectdb(provider.c_str()); | ||
191 | - ConnStatusType t = PQstatus(pPGconn); | ||
192 | - if (t != CONNECTION_OK) | ||
193 | - return false; | ||
194 | - int re = PQsetClientEncoding(pPGconn, "UTF-8"); | ||
195 | - | ||
196 | - std::string sql = "select t.f_geometry_column, t.type ,f_table_schema,t.srid from public.geometry_columns t where lower( t.f_table_name) = lower('" + name_ + "');"; | ||
197 | - PGresult* pPGresult= PQexec(pPGconn, sql.c_str()); | 210 | + if (provider.size() < 50) |
211 | + return false; | ||
212 | + isinit_ = true; | ||
213 | + //临时测试使用 | ||
214 | + PGconn *pPGconn = PQconnectdb(provider.c_str()); | ||
215 | + ConnStatusType t = PQstatus(pPGconn); | ||
216 | + if (t != CONNECTION_OK) | ||
217 | + return false; | ||
218 | + int re = PQsetClientEncoding(pPGconn, "UTF-8"); | ||
219 | + | ||
220 | + std::string sql = "select t.f_geometry_column, t.type ,f_table_schema,t.srid from public.geometry_columns t where lower( t.f_table_name) = lower('" + name_ + "');"; | ||
221 | + PGresult *pPGresult = PQexec(pPGconn, sql.c_str()); | ||
198 | char *sz = PQerrorMessage(pPGconn); | 222 | char *sz = PQerrorMessage(pPGconn); |
199 | - if(sz != nullptr && strcmp(sz,"") !=0) | ||
200 | - { | ||
201 | - PQfinish(pPGconn); return false; | ||
202 | - } | ||
203 | - | ||
204 | - int rowCount = PQntuples(pPGresult); | ||
205 | - if(rowCount<1) | ||
206 | - { | ||
207 | - PQfinish(pPGconn); return false; | ||
208 | - } | ||
209 | - | ||
210 | - geom_ = PQgetvalue(pPGresult, 0, 0); | ||
211 | - const char* geomtype = PQgetvalue(pPGresult, 0, 1); | ||
212 | - schema_ = PQgetvalue(pPGresult, 0, 2); | ||
213 | - //std::string srid = PQgetvalue(pPGresult, 0, 3); | 223 | + if (sz != nullptr && strcmp(sz, "") != 0) |
224 | + { | ||
225 | + PQfinish(pPGconn); | ||
226 | + return false; | ||
227 | + } | ||
228 | + | ||
229 | + int rowCount = PQntuples(pPGresult); | ||
230 | + if (rowCount < 1) | ||
231 | + { | ||
232 | + PQfinish(pPGconn); | ||
233 | + return false; | ||
234 | + } | ||
235 | + | ||
236 | + geom_ = PQgetvalue(pPGresult, 0, 0); | ||
237 | + const char *geomtype = PQgetvalue(pPGresult, 0, 1); | ||
238 | + schema_ = PQgetvalue(pPGresult, 0, 2); | ||
239 | + std::string srid = PQgetvalue(pPGresult, 0, 3); | ||
214 | wkbTypeString_ = geomtype; | 240 | wkbTypeString_ = geomtype; |
241 | + srid_ = srid; | ||
215 | if (!geomtype) | 242 | if (!geomtype) |
216 | return false; | 243 | return false; |
217 | - if (!strcmp(geomtype, "POINT")) wkbType_ = DmpWkbTypes::Point; | ||
218 | - else if (!strcmp(geomtype, "MULTIPOINT")) wkbType_ = DmpWkbTypes::MultiPoint; | ||
219 | - else if (!strcmp(geomtype, "LINESTRING")) wkbType_ = DmpWkbTypes::LineString; | ||
220 | - else if (!strcmp(geomtype, "MULTILINESTRING"))wkbType_ = DmpWkbTypes::MultiLineString; | ||
221 | - else if (!strcmp(geomtype, "POLYGON")) wkbType_ = DmpWkbTypes::Polygon; | ||
222 | - else if (!strcmp(geomtype, "MULTIPOLYGON")) wkbType_ = DmpWkbTypes::MultiPolygon; | ||
223 | - else if (!strcmp(geomtype, "GEOMETRY")) wkbType_ = DmpWkbTypes::Unknown; | ||
224 | - PQclear(pPGresult); pPGresult = NULL; | 244 | + if (!strcmp(geomtype, "POINT")) |
245 | + wkbType_ = DmpWkbTypes::Point; | ||
246 | + else if (!strcmp(geomtype, "MULTIPOINT")) | ||
247 | + wkbType_ = DmpWkbTypes::MultiPoint; | ||
248 | + else if (!strcmp(geomtype, "LINESTRING")) | ||
249 | + wkbType_ = DmpWkbTypes::LineString; | ||
250 | + else if (!strcmp(geomtype, "MULTILINESTRING")) | ||
251 | + wkbType_ = DmpWkbTypes::MultiLineString; | ||
252 | + else if (!strcmp(geomtype, "POLYGON")) | ||
253 | + wkbType_ = DmpWkbTypes::Polygon; | ||
254 | + else if (!strcmp(geomtype, "MULTIPOLYGON")) | ||
255 | + wkbType_ = DmpWkbTypes::MultiPolygon; | ||
256 | + else if (!strcmp(geomtype, "GEOMETRY")) | ||
257 | + wkbType_ = DmpWkbTypes::Unknown; | ||
258 | + PQclear(pPGresult); | ||
259 | + pPGresult = NULL; | ||
225 | PQfinish(pPGconn); | 260 | PQfinish(pPGconn); |
226 | - | ||
227 | - return true; | ||
228 | - | ||
229 | - | ||
230 | - providerKey_ = provider; | ||
231 | - delete dataProvider_; | ||
232 | - | ||
233 | - dataProvider_ = dynamic_cast<DmpVectorDataProvider *>(DmpProviderRegistry::Instance(provider)->CreateProvider(provider, dataSource_)); | ||
234 | - if (!dataProvider_) | ||
235 | - { | ||
236 | - isValid_ = false; | ||
237 | - return false; | ||
238 | - } | ||
239 | - isValid_ = dataProvider_->IsValid() | ||
240 | - ; | ||
241 | - if (!isValid_) | ||
242 | - { | ||
243 | - return false; | ||
244 | - } | ||
245 | - wkbType_ = dataProvider_->WkbType(); | ||
246 | - return true; | ||
247 | -} | ||
248 | 261 | ||
249 | - shared_ptr<DmpVectorThinLayer> DmpVectorLayer::GetCurrentScaleTable(double dx) | 262 | + return true; |
263 | + | ||
264 | + providerKey_ = provider; | ||
265 | + delete dataProvider_; | ||
266 | + | ||
267 | + dataProvider_ = dynamic_cast<DmpVectorDataProvider *>(DmpProviderRegistry::Instance(provider)->CreateProvider(provider, dataSource_)); | ||
268 | + if (!dataProvider_) | ||
250 | { | 269 | { |
251 | - | ||
252 | -/* | 270 | + isValid_ = false; |
271 | + return false; | ||
272 | + } | ||
273 | + isValid_ = dataProvider_->IsValid(); | ||
274 | + if (!isValid_) | ||
275 | + { | ||
276 | + return false; | ||
277 | + } | ||
278 | + wkbType_ = dataProvider_->WkbType(); | ||
279 | + return true; | ||
280 | +} | ||
281 | + | ||
282 | +shared_ptr<DmpVectorThinLayer> DmpVectorLayer::GetCurrentScaleTable(double dx) | ||
283 | +{ | ||
284 | + | ||
285 | + /* | ||
253 | int outTime = 600; | 286 | int outTime = 600; |
254 | if(this->dataCount >500000 && this->m_pDataset->m_MapLayerThinning.size() ==0) | 287 | if(this->dataCount >500000 && this->m_pDataset->m_MapLayerThinning.size() ==0) |
255 | { | 288 | { |
@@ -272,14 +305,14 @@ bool DmpVectorLayer::setDataProvider(std::string const &provider) | @@ -272,14 +305,14 @@ bool DmpVectorLayer::setDataProvider(std::string const &provider) | ||
272 | } | 305 | } |
273 | */ | 306 | */ |
274 | 307 | ||
275 | - for(int i =0; i< this->thinLayers_.size(); i++) | ||
276 | - { | ||
277 | - shared_ptr<DmpVectorThinLayer> mapLayerThinning = this->thinLayers_[i]; | 308 | + for (int i = 0; i < this->thinLayers_.size(); i++) |
309 | + { | ||
310 | + shared_ptr<DmpVectorThinLayer> mapLayerThinning = this->thinLayers_[i]; | ||
278 | 311 | ||
279 | - if(mapLayerThinning->IsCurrentLayer(dx)) | ||
280 | - { | ||
281 | - return mapLayerThinning; | ||
282 | - } | 312 | + if (mapLayerThinning->IsCurrentLayer(dx)) |
313 | + { | ||
314 | + return mapLayerThinning; | ||
283 | } | 315 | } |
284 | - return nullptr; | ||
285 | - } | ||
316 | + } | ||
317 | + return nullptr; | ||
318 | +} |
@@ -61,6 +61,7 @@ class CORE_EXPORT DmpVectorLayer : public DmpMapLayer | @@ -61,6 +61,7 @@ class CORE_EXPORT DmpVectorLayer : public DmpMapLayer | ||
61 | std::string geom() { return geom_;} | 61 | std::string geom() { return geom_;} |
62 | std::string wherestr() { return wherestr_;} | 62 | std::string wherestr() { return wherestr_;} |
63 | std::string GeomTypeString(){return wkbTypeString_;} | 63 | std::string GeomTypeString(){return wkbTypeString_;} |
64 | + std::string srid(){return srid_;} | ||
64 | size_t featurecount(){return featurecount_;} | 65 | size_t featurecount(){return featurecount_;} |
65 | bool IsInit(){return isinit_;} | 66 | bool IsInit(){return isinit_;} |
66 | private: | 67 | private: |
@@ -73,6 +74,7 @@ class CORE_EXPORT DmpVectorLayer : public DmpMapLayer | @@ -73,6 +74,7 @@ class CORE_EXPORT DmpVectorLayer : public DmpMapLayer | ||
73 | std::string geom_; | 74 | std::string geom_; |
74 | size_t featurecount_; | 75 | size_t featurecount_; |
75 | std::string wkbTypeString_; | 76 | std::string wkbTypeString_; |
77 | + std::string srid_; | ||
76 | 78 | ||
77 | std::string wherestr_; | 79 | std::string wherestr_; |
78 | bool isinit_ = false; | 80 | bool isinit_ = false; |
@@ -32,6 +32,7 @@ SET (DMAP_SERVER_SRCS | @@ -32,6 +32,7 @@ SET (DMAP_SERVER_SRCS | ||
32 | dmpserverparameters.cpp | 32 | dmpserverparameters.cpp |
33 | dmpserverplugins.cpp | 33 | dmpserverplugins.cpp |
34 | dmpserverutils.cpp | 34 | dmpserverutils.cpp |
35 | + dmpserverdes.cpp | ||
35 | dmpserverloader.cpp | 36 | dmpserverloader.cpp |
36 | dmpserverproject.cpp | 37 | dmpserverproject.cpp |
37 | dmpserverregistry.cpp | 38 | dmpserverregistry.cpp |
@@ -62,6 +63,7 @@ SET (DMAP_SERVER_HDRS | @@ -62,6 +63,7 @@ SET (DMAP_SERVER_HDRS | ||
62 | dmpserverparameters.h | 63 | dmpserverparameters.h |
63 | dmpserverplugins.h | 64 | dmpserverplugins.h |
64 | dmpserverutils.h | 65 | dmpserverutils.h |
66 | + dmpserverdes.h | ||
65 | dmpservice.h | 67 | dmpservice.h |
66 | dmpservermodule.h | 68 | dmpservermodule.h |
67 | dmpserverloader.h | 69 | dmpserverloader.h |
@@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
10 | #include <iostream> | 10 | #include <iostream> |
11 | #include "dmpserverconfig.h" | 11 | #include "dmpserverconfig.h" |
12 | #include "dmpapplication.h" | 12 | #include "dmpapplication.h" |
13 | - | 13 | +#include "dmphttputils.h" |
14 | DmpServerConfig::DmpServerConfig() | 14 | DmpServerConfig::DmpServerConfig() |
15 | { | 15 | { |
16 | std::string iniFile = DmpApplication::Instance()->libexecPath() + iniFileName_; | 16 | std::string iniFile = DmpApplication::Instance()->libexecPath() + iniFileName_; |
@@ -82,4 +82,14 @@ std::string DmpServerConfig::getValue(const std::string §ion,const std::stri | @@ -82,4 +82,14 @@ std::string DmpServerConfig::getValue(const std::string §ion,const std::stri | ||
82 | std::cerr << "Exception: " << e.what() << "\n"; | 82 | std::cerr << "Exception: " << e.what() << "\n"; |
83 | } | 83 | } |
84 | return value; | 84 | return value; |
85 | +} | ||
86 | + | ||
87 | +std::string DmpServerConfig::HttpPost(const std::string& url, std::string& postData) | ||
88 | +{ | ||
89 | + return DmpHttp::post(url, postData); | ||
90 | +} | ||
91 | + | ||
92 | +std::string DmpServerConfig::HttpGet(const std::string& url) | ||
93 | +{ | ||
94 | + return DmpHttp::get(url); | ||
85 | } | 95 | } |
@@ -22,6 +22,9 @@ public: | @@ -22,6 +22,9 @@ public: | ||
22 | std::string getPqsqlConnect(); | 22 | std::string getPqsqlConnect(); |
23 | std::string getMetaUrl(); | 23 | std::string getMetaUrl(); |
24 | std::string getValue(const std::string §ion,const std::string &key); | 24 | std::string getValue(const std::string §ion,const std::string &key); |
25 | + | ||
26 | + std::string HttpPost(const std::string& url, std::string& postData); | ||
27 | + std::string HttpGet(const std::string& url); | ||
25 | private: | 28 | private: |
26 | DmpServerConfig(); | 29 | DmpServerConfig(); |
27 | boost::property_tree::ptree ptIni_; | 30 | boost::property_tree::ptree ptIni_; |
src/server/dmpserverdes.cpp
0 → 100644
1 | +/************************************************************************** | ||
2 | +* file: dmpserverdes.cpp | ||
3 | + | ||
4 | +* Author: qingxiongf | ||
5 | +* Date: 2022-01-13 19:20:30 | ||
6 | +* Email: qingxiongf@chinadci.com | ||
7 | +* copyright: 广州城市信息研究所有限公司 | ||
8 | +***************************************************************************/ | ||
9 | +#include "dmpserverdes.h" | ||
10 | +#include "dmpserverutils.h" | ||
11 | + | ||
12 | +//std::string RsaBase64Encrypt(const std::string &source, const char* key) | ||
13 | +//{ | ||
14 | +//} | ||
15 | + | ||
16 | +std::string DmpServerDes::DesBase64Decrypt(const std::string &source, const char* key) | ||
17 | +{ | ||
18 | + // char key[] = "Chinadci"; | ||
19 | + char decry[1000] = {0}; | ||
20 | + std::string decbase64_source; | ||
21 | + if(!DmpServerUtils::Base64Decode(source, &decbase64_source)) | ||
22 | + { | ||
23 | + return ""; | ||
24 | + } | ||
25 | + int size = decbase64_source.size(); | ||
26 | + for(; size>0; size--) | ||
27 | + { | ||
28 | + if(decbase64_source[size-1] != 0)break; | ||
29 | + } | ||
30 | + DmpServerDes rsa2048; | ||
31 | + rsa2048.Decrypt((unsigned char *)decbase64_source.c_str(), size, (unsigned char *)key, (unsigned char *)decry); | ||
32 | + for (size_t i = 0; i < strlen(decry) && i < 1000; i++) | ||
33 | + { | ||
34 | + if (decry[i] == '\b') | ||
35 | + { | ||
36 | + decry[i] = '\0'; | ||
37 | + break; | ||
38 | + } | ||
39 | + } | ||
40 | + return decry; | ||
41 | +} | ||
42 | + | ||
43 | + | ||
44 | +void DmpServerDes::generate_key(unsigned char *key) | ||
45 | +{ | ||
46 | + int i; | ||
47 | + for (i = 0; i < 8; i++) | ||
48 | + { | ||
49 | + key[i] = rand() % 255; | ||
50 | + } | ||
51 | +} | ||
52 | + | ||
53 | +void DmpServerDes::generate_sub_keys(unsigned char *main_key, key_set *key_sets) | ||
54 | +{ | ||
55 | + int initial_key_permutaion[] = {57, 49, 41, 33, 25, 17, 9, | ||
56 | + 1, 58, 50, 42, 34, 26, 18, | ||
57 | + 10, 2, 59, 51, 43, 35, 27, | ||
58 | + 19, 11, 3, 60, 52, 44, 36, | ||
59 | + 63, 55, 47, 39, 31, 23, 15, | ||
60 | + 7, 62, 54, 46, 38, 30, 22, | ||
61 | + 14, 6, 61, 53, 45, 37, 29, | ||
62 | + 21, 13, 5, 28, 20, 12, 4}; | ||
63 | + | ||
64 | + int key_shift_sizes[] = {-1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1}; | ||
65 | + | ||
66 | + int sub_key_permutation[] = {14, 17, 11, 24, 1, 5, | ||
67 | + 3, 28, 15, 6, 21, 10, | ||
68 | + 23, 19, 12, 4, 26, 8, | ||
69 | + 16, 7, 27, 20, 13, 2, | ||
70 | + 41, 52, 31, 37, 47, 55, | ||
71 | + 30, 40, 51, 45, 33, 48, | ||
72 | + 44, 49, 39, 56, 34, 53, | ||
73 | + 46, 42, 50, 36, 29, 32}; | ||
74 | + | ||
75 | + int i, j; | ||
76 | + int shift_size; | ||
77 | + unsigned char shift_byte, first_shift_bits, second_shift_bits, third_shift_bits, fourth_shift_bits; | ||
78 | + | ||
79 | + memset(key_sets, 0, sizeof(key_set) * 17); | ||
80 | + for (i = 0; i < 8; i++) | ||
81 | + { | ||
82 | + key_sets[0].k[i] = 0; | ||
83 | + } | ||
84 | + | ||
85 | + for (i = 0; i < 56; i++) | ||
86 | + { | ||
87 | + shift_size = initial_key_permutaion[i]; | ||
88 | + shift_byte = 0x80 >> ((shift_size - 1) % 8); | ||
89 | + shift_byte &= main_key[(shift_size - 1) / 8]; | ||
90 | + shift_byte <<= ((shift_size - 1) % 8); | ||
91 | + | ||
92 | + key_sets[0].k[i / 8] |= (shift_byte >> i % 8); | ||
93 | + } | ||
94 | + | ||
95 | + for (i = 0; i < 3; i++) | ||
96 | + { | ||
97 | + key_sets[0].c[i] = key_sets[0].k[i]; | ||
98 | + } | ||
99 | + | ||
100 | + key_sets[0].c[3] = key_sets[0].k[3] & 0xF0; | ||
101 | + | ||
102 | + for (i = 0; i < 3; i++) | ||
103 | + { | ||
104 | + key_sets[0].d[i] = (key_sets[0].k[i + 3] & 0x0F) << 4; | ||
105 | + key_sets[0].d[i] |= (key_sets[0].k[i + 4] & 0xF0) >> 4; | ||
106 | + } | ||
107 | + | ||
108 | + key_sets[0].d[3] = (key_sets[0].k[6] & 0x0F) << 4; | ||
109 | + | ||
110 | + for (i = 1; i < 17; i++) | ||
111 | + { | ||
112 | + for (j = 0; j < 4; j++) | ||
113 | + { | ||
114 | + key_sets[i].c[j] = key_sets[i - 1].c[j]; | ||
115 | + key_sets[i].d[j] = key_sets[i - 1].d[j]; | ||
116 | + } | ||
117 | + | ||
118 | + shift_size = key_shift_sizes[i]; | ||
119 | + if (shift_size == 1) | ||
120 | + { | ||
121 | + shift_byte = 0x80; | ||
122 | + } | ||
123 | + else | ||
124 | + { | ||
125 | + shift_byte = 0xC0; | ||
126 | + } | ||
127 | + | ||
128 | + // Process C | ||
129 | + first_shift_bits = shift_byte & key_sets[i].c[0]; | ||
130 | + second_shift_bits = shift_byte & key_sets[i].c[1]; | ||
131 | + third_shift_bits = shift_byte & key_sets[i].c[2]; | ||
132 | + fourth_shift_bits = shift_byte & key_sets[i].c[3]; | ||
133 | + | ||
134 | + key_sets[i].c[0] <<= shift_size; | ||
135 | + key_sets[i].c[0] |= (second_shift_bits >> (8 - shift_size)); | ||
136 | + | ||
137 | + key_sets[i].c[1] <<= shift_size; | ||
138 | + key_sets[i].c[1] |= (third_shift_bits >> (8 - shift_size)); | ||
139 | + | ||
140 | + key_sets[i].c[2] <<= shift_size; | ||
141 | + key_sets[i].c[2] |= (fourth_shift_bits >> (8 - shift_size)); | ||
142 | + | ||
143 | + key_sets[i].c[3] <<= shift_size; | ||
144 | + key_sets[i].c[3] |= (first_shift_bits >> (4 - shift_size)); | ||
145 | + | ||
146 | + // Process D | ||
147 | + first_shift_bits = shift_byte & key_sets[i].d[0]; | ||
148 | + second_shift_bits = shift_byte & key_sets[i].d[1]; | ||
149 | + third_shift_bits = shift_byte & key_sets[i].d[2]; | ||
150 | + fourth_shift_bits = shift_byte & key_sets[i].d[3]; | ||
151 | + | ||
152 | + key_sets[i].d[0] <<= shift_size; | ||
153 | + key_sets[i].d[0] |= (second_shift_bits >> (8 - shift_size)); | ||
154 | + | ||
155 | + key_sets[i].d[1] <<= shift_size; | ||
156 | + key_sets[i].d[1] |= (third_shift_bits >> (8 - shift_size)); | ||
157 | + | ||
158 | + key_sets[i].d[2] <<= shift_size; | ||
159 | + key_sets[i].d[2] |= (fourth_shift_bits >> (8 - shift_size)); | ||
160 | + | ||
161 | + key_sets[i].d[3] <<= shift_size; | ||
162 | + key_sets[i].d[3] |= (first_shift_bits >> (4 - shift_size)); | ||
163 | + | ||
164 | + for (j = 0; j < 48; j++) | ||
165 | + { | ||
166 | + shift_size = sub_key_permutation[j]; | ||
167 | + if (shift_size <= 28) | ||
168 | + { | ||
169 | + shift_byte = 0x80 >> ((shift_size - 1) % 8); | ||
170 | + shift_byte &= key_sets[i].c[(shift_size - 1) / 8]; | ||
171 | + shift_byte <<= ((shift_size - 1) % 8); | ||
172 | + } | ||
173 | + else | ||
174 | + { | ||
175 | + shift_byte = 0x80 >> ((shift_size - 29) % 8); | ||
176 | + shift_byte &= key_sets[i].d[(shift_size - 29) / 8]; | ||
177 | + shift_byte <<= ((shift_size - 29) % 8); | ||
178 | + } | ||
179 | + | ||
180 | + key_sets[i].k[j / 8] |= (shift_byte >> j % 8); | ||
181 | + } | ||
182 | + } | ||
183 | +} | ||
184 | + | ||
185 | +void DmpServerDes::process_message(unsigned char *message_piece, unsigned char *processed_piece, key_set *key_sets, int mode) | ||
186 | +{ | ||
187 | + | ||
188 | + int initial_message_permutation[] = {58, 50, 42, 34, 26, 18, 10, 2, | ||
189 | + 60, 52, 44, 36, 28, 20, 12, 4, | ||
190 | + 62, 54, 46, 38, 30, 22, 14, 6, | ||
191 | + 64, 56, 48, 40, 32, 24, 16, 8, | ||
192 | + 57, 49, 41, 33, 25, 17, 9, 1, | ||
193 | + 59, 51, 43, 35, 27, 19, 11, 3, | ||
194 | + 61, 53, 45, 37, 29, 21, 13, 5, | ||
195 | + 63, 55, 47, 39, 31, 23, 15, 7}; | ||
196 | + | ||
197 | + int message_expansion[] = {32, 1, 2, 3, 4, 5, | ||
198 | + 4, 5, 6, 7, 8, 9, | ||
199 | + 8, 9, 10, 11, 12, 13, | ||
200 | + 12, 13, 14, 15, 16, 17, | ||
201 | + 16, 17, 18, 19, 20, 21, | ||
202 | + 20, 21, 22, 23, 24, 25, | ||
203 | + 24, 25, 26, 27, 28, 29, | ||
204 | + 28, 29, 30, 31, 32, 1}; | ||
205 | + int S1[] = {14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, | ||
206 | + 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, | ||
207 | + 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, | ||
208 | + 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13}; | ||
209 | + | ||
210 | + int S2[] = {15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, | ||
211 | + 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, | ||
212 | + 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, | ||
213 | + 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9}; | ||
214 | + | ||
215 | + int S3[] = {10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, | ||
216 | + 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, | ||
217 | + 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, | ||
218 | + 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12}; | ||
219 | + | ||
220 | + int S4[] = {7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, | ||
221 | + 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, | ||
222 | + 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, | ||
223 | + 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14}; | ||
224 | + | ||
225 | + int S5[] = {2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, | ||
226 | + 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, | ||
227 | + 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, | ||
228 | + 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3}; | ||
229 | + | ||
230 | + int S6[] = {12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, | ||
231 | + 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, | ||
232 | + 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, | ||
233 | + 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13}; | ||
234 | + | ||
235 | + int S7[] = {4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, | ||
236 | + 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, | ||
237 | + 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, | ||
238 | + 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12}; | ||
239 | + | ||
240 | + int S8[] = {13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, | ||
241 | + 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, | ||
242 | + 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, | ||
243 | + 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}; | ||
244 | + | ||
245 | + int right_sub_message_permutation[] = {16, 7, 20, 21, | ||
246 | + 29, 12, 28, 17, | ||
247 | + 1, 15, 23, 26, | ||
248 | + 5, 18, 31, 10, | ||
249 | + 2, 8, 24, 14, | ||
250 | + 32, 27, 3, 9, | ||
251 | + 19, 13, 30, 6, | ||
252 | + 22, 11, 4, 25}; | ||
253 | + int final_message_permutation[] = {40, 8, 48, 16, 56, 24, 64, 32, | ||
254 | + 39, 7, 47, 15, 55, 23, 63, 31, | ||
255 | + 38, 6, 46, 14, 54, 22, 62, 30, | ||
256 | + 37, 5, 45, 13, 53, 21, 61, 29, | ||
257 | + 36, 4, 44, 12, 52, 20, 60, 28, | ||
258 | + 35, 3, 43, 11, 51, 19, 59, 27, | ||
259 | + 34, 2, 42, 10, 50, 18, 58, 26, | ||
260 | + 33, 1, 41, 9, 49, 17, 57, 25}; | ||
261 | + int i, k; | ||
262 | + int shift_size; | ||
263 | + unsigned char shift_byte; | ||
264 | + | ||
265 | + unsigned char initial_permutation[8]; | ||
266 | + memset(initial_permutation, 0, 8); | ||
267 | + memset(processed_piece, 0, 8); | ||
268 | + | ||
269 | + for (i = 0; i < 64; i++) | ||
270 | + { | ||
271 | + shift_size = initial_message_permutation[i]; | ||
272 | + shift_byte = 0x80 >> ((shift_size - 1) % 8); | ||
273 | + shift_byte &= message_piece[(shift_size - 1) / 8]; | ||
274 | + shift_byte <<= ((shift_size - 1) % 8); | ||
275 | + | ||
276 | + initial_permutation[i / 8] |= (shift_byte >> i % 8); | ||
277 | + } | ||
278 | + | ||
279 | + unsigned char l[4], r[4]; | ||
280 | + for (i = 0; i < 4; i++) | ||
281 | + { | ||
282 | + l[i] = initial_permutation[i]; | ||
283 | + r[i] = initial_permutation[i + 4]; | ||
284 | + } | ||
285 | + | ||
286 | + unsigned char ln[4], rn[4], er[6], ser[4]; | ||
287 | + | ||
288 | + int key_index; | ||
289 | + for (k = 1; k <= 16; k++) | ||
290 | + { | ||
291 | + memcpy(ln, r, 4); | ||
292 | + | ||
293 | + memset(er, 0, 6); | ||
294 | + | ||
295 | + for (i = 0; i < 48; i++) | ||
296 | + { | ||
297 | + shift_size = message_expansion[i]; | ||
298 | + shift_byte = 0x80 >> ((shift_size - 1) % 8); | ||
299 | + shift_byte &= r[(shift_size - 1) / 8]; | ||
300 | + shift_byte <<= ((shift_size - 1) % 8); | ||
301 | + | ||
302 | + er[i / 8] |= (shift_byte >> i % 8); | ||
303 | + } | ||
304 | + | ||
305 | + if (mode == DECRYPTION_MODE) | ||
306 | + { | ||
307 | + key_index = 17 - k; | ||
308 | + } | ||
309 | + else | ||
310 | + { | ||
311 | + key_index = k; | ||
312 | + } | ||
313 | + | ||
314 | + for (i = 0; i < 6; i++) | ||
315 | + { | ||
316 | + er[i] ^= key_sets[key_index].k[i]; | ||
317 | + } | ||
318 | + | ||
319 | + unsigned char row, column; | ||
320 | + | ||
321 | + for (i = 0; i < 4; i++) | ||
322 | + { | ||
323 | + ser[i] = 0; | ||
324 | + } | ||
325 | + | ||
326 | + // 0000 0000 0000 0000 0000 0000 | ||
327 | + // rccc crrc cccr rccc crrc cccr | ||
328 | + | ||
329 | + // Byte 1 | ||
330 | + row = 0; | ||
331 | + row |= ((er[0] & 0x80) >> 6); | ||
332 | + row |= ((er[0] & 0x04) >> 2); | ||
333 | + | ||
334 | + column = 0; | ||
335 | + column |= ((er[0] & 0x78) >> 3); | ||
336 | + | ||
337 | + ser[0] |= ((unsigned char)S1[row * 16 + column] << 4); | ||
338 | + | ||
339 | + row = 0; | ||
340 | + row |= (er[0] & 0x02); | ||
341 | + row |= ((er[1] & 0x10) >> 4); | ||
342 | + | ||
343 | + column = 0; | ||
344 | + column |= ((er[0] & 0x01) << 3); | ||
345 | + column |= ((er[1] & 0xE0) >> 5); | ||
346 | + | ||
347 | + ser[0] |= (unsigned char)S2[row * 16 + column]; | ||
348 | + | ||
349 | + // Byte 2 | ||
350 | + row = 0; | ||
351 | + row |= ((er[1] & 0x08) >> 2); | ||
352 | + row |= ((er[2] & 0x40) >> 6); | ||
353 | + | ||
354 | + column = 0; | ||
355 | + column |= ((er[1] & 0x07) << 1); | ||
356 | + column |= ((er[2] & 0x80) >> 7); | ||
357 | + | ||
358 | + ser[1] |= ((unsigned char)S3[row * 16 + column] << 4); | ||
359 | + | ||
360 | + row = 0; | ||
361 | + row |= ((er[2] & 0x20) >> 4); | ||
362 | + row |= (er[2] & 0x01); | ||
363 | + | ||
364 | + column = 0; | ||
365 | + column |= ((er[2] & 0x1E) >> 1); | ||
366 | + | ||
367 | + ser[1] |= (unsigned char)S4[row * 16 + column]; | ||
368 | + | ||
369 | + // Byte 3 | ||
370 | + row = 0; | ||
371 | + row |= ((er[3] & 0x80) >> 6); | ||
372 | + row |= ((er[3] & 0x04) >> 2); | ||
373 | + | ||
374 | + column = 0; | ||
375 | + column |= ((er[3] & 0x78) >> 3); | ||
376 | + | ||
377 | + ser[2] |= ((unsigned char)S5[row * 16 + column] << 4); | ||
378 | + | ||
379 | + row = 0; | ||
380 | + row |= (er[3] & 0x02); | ||
381 | + row |= ((er[4] & 0x10) >> 4); | ||
382 | + | ||
383 | + column = 0; | ||
384 | + column |= ((er[3] & 0x01) << 3); | ||
385 | + column |= ((er[4] & 0xE0) >> 5); | ||
386 | + | ||
387 | + ser[2] |= (unsigned char)S6[row * 16 + column]; | ||
388 | + | ||
389 | + // Byte 4 | ||
390 | + row = 0; | ||
391 | + row |= ((er[4] & 0x08) >> 2); | ||
392 | + row |= ((er[5] & 0x40) >> 6); | ||
393 | + | ||
394 | + column = 0; | ||
395 | + column |= ((er[4] & 0x07) << 1); | ||
396 | + column |= ((er[5] & 0x80) >> 7); | ||
397 | + | ||
398 | + ser[3] |= ((unsigned char)S7[row * 16 + column] << 4); | ||
399 | + | ||
400 | + row = 0; | ||
401 | + row |= ((er[5] & 0x20) >> 4); | ||
402 | + row |= (er[5] & 0x01); | ||
403 | + | ||
404 | + column = 0; | ||
405 | + column |= ((er[5] & 0x1E) >> 1); | ||
406 | + | ||
407 | + ser[3] |= (unsigned char)S8[row * 16 + column]; | ||
408 | + | ||
409 | + for (i = 0; i < 4; i++) | ||
410 | + { | ||
411 | + rn[i] = 0; | ||
412 | + } | ||
413 | + | ||
414 | + for (i = 0; i < 32; i++) | ||
415 | + { | ||
416 | + shift_size = right_sub_message_permutation[i]; | ||
417 | + shift_byte = 0x80 >> ((shift_size - 1) % 8); | ||
418 | + shift_byte &= ser[(shift_size - 1) / 8]; | ||
419 | + shift_byte <<= ((shift_size - 1) % 8); | ||
420 | + | ||
421 | + rn[i / 8] |= (shift_byte >> i % 8); | ||
422 | + } | ||
423 | + | ||
424 | + for (i = 0; i < 4; i++) | ||
425 | + { | ||
426 | + rn[i] ^= l[i]; | ||
427 | + } | ||
428 | + | ||
429 | + for (i = 0; i < 4; i++) | ||
430 | + { | ||
431 | + l[i] = ln[i]; | ||
432 | + r[i] = rn[i]; | ||
433 | + } | ||
434 | + } | ||
435 | + | ||
436 | + unsigned char pre_end_permutation[8]; | ||
437 | + for (i = 0; i < 4; i++) | ||
438 | + { | ||
439 | + pre_end_permutation[i] = r[i]; | ||
440 | + pre_end_permutation[4 + i] = l[i]; | ||
441 | + } | ||
442 | + | ||
443 | + for (i = 0; i < 64; i++) | ||
444 | + { | ||
445 | + shift_size = final_message_permutation[i]; | ||
446 | + shift_byte = 0x80 >> ((shift_size - 1) % 8); | ||
447 | + shift_byte &= pre_end_permutation[(shift_size - 1) / 8]; | ||
448 | + shift_byte <<= ((shift_size - 1) % 8); | ||
449 | + | ||
450 | + processed_piece[i / 8] |= (shift_byte >> i % 8); | ||
451 | + } | ||
452 | +} | ||
453 | + | ||
454 | +void DmpServerDes::copyUChar(unsigned char *data_block, unsigned char *source, int loc, int num) | ||
455 | +{ | ||
456 | + int i; | ||
457 | + for (i = 0; i < num; i++) | ||
458 | + { | ||
459 | + data_block[i] = source[loc + i]; | ||
460 | + } | ||
461 | +} | ||
462 | + | ||
463 | +bool DmpServerDes::Encrypt(unsigned char *source, unsigned char *des_key, unsigned char *destination) | ||
464 | +{ | ||
465 | + | ||
466 | + // Generate DES key set******************************************* | ||
467 | + int padding; | ||
468 | + int block_count = 0, number_of_blocks; | ||
469 | + | ||
470 | + unsigned char data_block[8]; | ||
471 | + unsigned char processed_block[8]; | ||
472 | + key_set *key_sets = (key_set *)malloc(17 * sizeof(key_set)); | ||
473 | + | ||
474 | + generate_sub_keys(des_key, key_sets); | ||
475 | + // Generate DES key set******************************************* | ||
476 | + | ||
477 | + int length = strlen((const char *)source); | ||
478 | + number_of_blocks = length / 8 + ((length % 8) ? 1 : 0); | ||
479 | + | ||
480 | + // Start read source word, encrypt to destination | ||
481 | + for (int i = 0; i < length; i += 8) | ||
482 | + { | ||
483 | + | ||
484 | + block_count++; | ||
485 | + | ||
486 | + if (block_count == number_of_blocks) | ||
487 | + { | ||
488 | + padding = 8 - length % 8; | ||
489 | + | ||
490 | + copyUChar(data_block, source, i, 8 - padding); | ||
491 | + if (padding < 8) | ||
492 | + { // Fill empty data block bytes with padding | ||
493 | + memset((data_block + 8 - padding), (unsigned char)padding, padding); | ||
494 | + } | ||
495 | + else if (padding == 8) | ||
496 | + { // Write an extra block for padding | ||
497 | + copyUChar(data_block, source, i, 8); | ||
498 | + } | ||
499 | + } | ||
500 | + else | ||
501 | + { | ||
502 | + copyUChar(data_block, source, i, 8); | ||
503 | + } | ||
504 | + | ||
505 | + process_message(data_block, processed_block, key_sets, ENCRYPTION_MODE); | ||
506 | + memcpy(destination + i, &processed_block, 8 * sizeof(char)); | ||
507 | + | ||
508 | + memset(data_block, 0, 8); | ||
509 | + } | ||
510 | + | ||
511 | + // Free up memory | ||
512 | + free(key_sets); | ||
513 | + | ||
514 | + return true; | ||
515 | +} | ||
516 | + | ||
517 | +bool DmpServerDes::Decrypt(unsigned char *source, int length, unsigned char *key, unsigned char *destination) | ||
518 | +{ | ||
519 | + | ||
520 | + // Generate DES key set******************************************* | ||
521 | + int padding; | ||
522 | + int block_count = 0, number_of_blocks; | ||
523 | + | ||
524 | + unsigned char data_block[8]; | ||
525 | + unsigned char processed_block[8]; | ||
526 | + key_set *key_sets = (key_set *)malloc(17 * sizeof(key_set)); | ||
527 | + | ||
528 | + generate_sub_keys(key, key_sets); | ||
529 | + // Generate DES key set******************************************* | ||
530 | + | ||
531 | + //int length = strlen((const char*)source); | ||
532 | + number_of_blocks = length / 8 + ((length % 8) ? 1 : 0); | ||
533 | + | ||
534 | + // Start read source word | ||
535 | + for (int i = 0; i < length; i += 8) | ||
536 | + { | ||
537 | + | ||
538 | + block_count++; | ||
539 | + | ||
540 | + if (block_count == number_of_blocks) | ||
541 | + { | ||
542 | + copyUChar(data_block, source, i, 8); | ||
543 | + process_message(data_block, processed_block, key_sets, DECRYPTION_MODE); | ||
544 | + padding = processed_block[7]; | ||
545 | + | ||
546 | + if (padding < 8) | ||
547 | + { | ||
548 | + memcpy(destination + i, &processed_block, (8 - padding) * sizeof(char)); | ||
549 | + } | ||
550 | + else | ||
551 | + { | ||
552 | + memcpy(destination + i, &processed_block, 8 * sizeof(char)); | ||
553 | + } | ||
554 | + } | ||
555 | + else | ||
556 | + { | ||
557 | + copyUChar(data_block, source, i, 8); | ||
558 | + process_message(data_block, processed_block, key_sets, DECRYPTION_MODE); | ||
559 | + memcpy(destination + i, &processed_block, 8 * sizeof(char)); | ||
560 | + } | ||
561 | + | ||
562 | + memset(data_block, 0, 8); | ||
563 | + } | ||
564 | + | ||
565 | + // Free up memory | ||
566 | + free(key_sets); | ||
567 | + | ||
568 | + return true; | ||
569 | +} |
src/server/dmpserverdes.h
0 → 100644
1 | +/************************************************************************** | ||
2 | +* file: dmpserverdes.h | ||
3 | + | ||
4 | +* Author: qingxiongf | ||
5 | +* Date: 2022-01-13 19:20:26 | ||
6 | +* Email: qingxiongf@chinadci.com | ||
7 | +* copyright: 广州城市信息研究所有限公司 | ||
8 | +***************************************************************************/ | ||
9 | + | ||
10 | +#ifndef __dmpserverdes_h__ | ||
11 | +#define __dmpserverdes_h__ | ||
12 | +#include "dmap_server.h" | ||
13 | +#include <boost/filesystem.hpp> | ||
14 | +#include <unordered_map> | ||
15 | + | ||
16 | +#define ENCRYPTION_MODE 1 | ||
17 | +#define DECRYPTION_MODE 0 | ||
18 | + | ||
19 | +class SERVER_EXPORT DmpServerDes | ||
20 | +{ | ||
21 | +public: | ||
22 | + typedef struct | ||
23 | + { | ||
24 | + unsigned char k[8]; | ||
25 | + unsigned char c[4]; | ||
26 | + unsigned char d[4]; | ||
27 | + } key_set; | ||
28 | + | ||
29 | + bool Encrypt(unsigned char *source, unsigned char *des_key, unsigned char *destination); | ||
30 | + bool Decrypt(unsigned char *source, int length, unsigned char *key, unsigned char *destination); | ||
31 | + | ||
32 | + // static std::string RsaBase64Encrypt(const std::string &source, const char* key); | ||
33 | + static std::string DesBase64Decrypt(const std::string &source, const char* key); | ||
34 | + | ||
35 | +private: | ||
36 | + void generate_key(unsigned char *key); | ||
37 | + void generate_sub_keys(unsigned char *main_key, key_set *key_sets); | ||
38 | + void process_message(unsigned char *message_piece, unsigned char *processed_piece, key_set *key_sets, int mode); | ||
39 | + void copyUChar(unsigned char *data_block, unsigned char *source, int loc, int num); | ||
40 | +}; | ||
41 | + | ||
42 | +#endif // __dmpserverdes_h__ |
@@ -7,7 +7,14 @@ | @@ -7,7 +7,14 @@ | ||
7 | * copyright: 广州城市信息研究所有限公司 | 7 | * copyright: 广州城市信息研究所有限公司 |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | #include "dmpmapserverutil.h" | 9 | #include "dmpmapserverutil.h" |
10 | -#include <string.h> | 10 | +#include <iostream> |
11 | +#include <istream> | ||
12 | +#include <ostream> | ||
13 | +#include <string> | ||
14 | +#include <boost/asio.hpp> | ||
15 | + | ||
16 | + | ||
17 | +using boost::asio::ip::tcp; | ||
11 | 18 | ||
12 | namespace mapserver | 19 | namespace mapserver |
13 | { | 20 | { |
@@ -281,4 +288,143 @@ void DmpMapServerUtil::responseGeojson(shared_ptr<DmpPgsql> pPgsqlConn, std::str | @@ -281,4 +288,143 @@ void DmpMapServerUtil::responseGeojson(shared_ptr<DmpPgsql> pPgsqlConn, std::str | ||
281 | return stringList; | 288 | return stringList; |
282 | 289 | ||
283 | } | 290 | } |
291 | + | ||
292 | + | ||
293 | + int DmpMapServerUtil::HttpPost(const std::string& url, std::string& postData, std::string &reponse_data) | ||
294 | + { | ||
295 | + string host, port,path; | ||
296 | + const std::string &http_ = "http://"; | ||
297 | + const std::string &https_ = "https://"; | ||
298 | + std::string temp_data = url; | ||
299 | + if (temp_data.find(http_) == 0) | ||
300 | + { | ||
301 | + temp_data = temp_data.substr(http_.length()); | ||
302 | + } | ||
303 | + else if (temp_data.find(https_) == 0) | ||
304 | + { | ||
305 | + temp_data = temp_data.substr(https_.length()); | ||
306 | + } | ||
307 | + else | ||
308 | + { | ||
309 | + return 500; | ||
310 | + } | ||
311 | + // 解析域名 | ||
312 | + std::size_t idx = temp_data.find('/'); | ||
313 | + // 解析 域名后的page | ||
314 | + if (std::string::npos == idx) | ||
315 | + { | ||
316 | + path = "/"; | ||
317 | + idx = temp_data.size(); | ||
318 | + } | ||
319 | + else | ||
320 | + { | ||
321 | + path = temp_data.substr(idx); | ||
322 | + } | ||
323 | + // 解析域名 | ||
324 | + host = temp_data.substr(0, idx); | ||
325 | + // 解析端口 | ||
326 | + idx = host.find(':'); | ||
327 | + if (std::string::npos == idx) | ||
328 | + { | ||
329 | + port = "80"; | ||
330 | + } | ||
331 | + else | ||
332 | + { | ||
333 | + port = host.substr(idx + 1); | ||
334 | + host = host.substr(0, idx); | ||
335 | + } | ||
336 | + | ||
337 | + | ||
338 | + try | ||
339 | + { | ||
340 | + boost::asio::io_service io_service; | ||
341 | + //如果io_service存在复用的情况 | ||
342 | + if (io_service.stopped()) | ||
343 | + io_service.reset(); | ||
344 | + | ||
345 | + // 从dns取得域名下的所有ip | ||
346 | + tcp::resolver resolver(io_service); | ||
347 | + tcp::resolver::query query(host, port); | ||
348 | + tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); | ||
349 | + | ||
350 | + // 尝试连接到其中的某个ip直到成功 | ||
351 | + tcp::socket socket(io_service); | ||
352 | + boost::asio::connect(socket, endpoint_iterator); | ||
353 | + | ||
354 | + // Form the request. We specify the "Connection: close" header so that the | ||
355 | + // server will close the socket after transmitting the response. This will | ||
356 | + // allow us to treat all data up until the EOF as the content. | ||
357 | + boost::asio::streambuf request; | ||
358 | + std::ostream request_stream(&request); | ||
359 | + request_stream << "POST " << path.c_str() << " HTTP/1.0\r\n"; | ||
360 | + request_stream << "Host: " << host << ":" << port << "\r\n"; | ||
361 | + request_stream << "Accept: */*\r\n"; | ||
362 | + request_stream << "Content-Length: " << postData.length() << "\r\n"; | ||
363 | + request_stream << "Content-Type: application/x-www-form-urlencoded\r\n"; | ||
364 | + request_stream << "Connection: close\r\n\r\n"; | ||
365 | + request_stream << postData.c_str(); | ||
366 | + | ||
367 | + // Send the request. | ||
368 | + boost::asio::write(socket, request); | ||
369 | + | ||
370 | + // Read the response status line. The response streambuf will automatically | ||
371 | + // grow to accommodate the entire line. The growth may be limited by passing | ||
372 | + // a maximum size to the streambuf constructor. | ||
373 | + boost::asio::streambuf response; | ||
374 | + boost::asio::read_until(socket, response, "\r\n"); | ||
375 | + | ||
376 | + // Check that response is OK. | ||
377 | + std::istream response_stream(&response); | ||
378 | + std::string http_version; | ||
379 | + response_stream >> http_version; | ||
380 | + unsigned int status_code; | ||
381 | + response_stream >> status_code; | ||
382 | + std::string status_message; | ||
383 | + std::getline(response_stream, status_message); | ||
384 | + if (!response_stream || http_version.substr(0, 5) != "HTTP/") | ||
385 | + { | ||
386 | + reponse_data = "Invalid response"; | ||
387 | + return -2; | ||
388 | + } | ||
389 | + // 如果服务器返回非200都认为有错,不支持301/302等跳转 | ||
390 | + if (status_code != 200) | ||
391 | + { | ||
392 | + reponse_data = "Response returned with status code != 200 "; | ||
393 | + return status_code; | ||
394 | + } | ||
395 | + | ||
396 | + // 传说中的包头可以读下来了 | ||
397 | + std::string header; | ||
398 | + std::vector<string> headers; | ||
399 | + while (std::getline(response_stream, header) && header != "\r") | ||
400 | + headers.push_back(header); | ||
401 | + | ||
402 | + // 读取所有剩下的数据作为包体 | ||
403 | + boost::system::error_code error; | ||
404 | + while (boost::asio::read(socket, response, | ||
405 | + boost::asio::transfer_at_least(1), error)) | ||
406 | + { | ||
407 | + } | ||
408 | + | ||
409 | + //响应有数据 | ||
410 | + if (response.size()) | ||
411 | + { | ||
412 | + std::istream response_stream(&response); | ||
413 | + std::istreambuf_iterator<char> eos; | ||
414 | + reponse_data = string(std::istreambuf_iterator<char>(response_stream), eos); | ||
415 | + } | ||
416 | + | ||
417 | + if (error != boost::asio::error::eof) | ||
418 | + { | ||
419 | + reponse_data = error.message(); | ||
420 | + return -3; | ||
421 | + } | ||
422 | + } | ||
423 | + catch (std::exception &e) | ||
424 | + { | ||
425 | + reponse_data = e.what(); | ||
426 | + return -4; | ||
427 | + } | ||
428 | + return 0; | ||
429 | + } | ||
284 | } | 430 | } |
@@ -14,6 +14,7 @@ | @@ -14,6 +14,7 @@ | ||
14 | #include <memory> | 14 | #include <memory> |
15 | #include "dmppgsqlsourcepools.h" | 15 | #include "dmppgsqlsourcepools.h" |
16 | 16 | ||
17 | + | ||
17 | namespace mapserver | 18 | namespace mapserver |
18 | { | 19 | { |
19 | class DmpMapServerUtil | 20 | class DmpMapServerUtil |
@@ -25,6 +26,8 @@ namespace mapserver | @@ -25,6 +26,8 @@ namespace mapserver | ||
25 | static std::string replace(std::string strsrc, std::string strfind, std::string strrep); | 26 | static std::string replace(std::string strsrc, std::string strfind, std::string strrep); |
26 | 27 | ||
27 | static std::vector<std::string> stringSplit(const std::string &str, const std::string &pattern); | 28 | static std::vector<std::string> stringSplit(const std::string &str, const std::string &pattern); |
29 | + | ||
30 | + static int HttpPost(const std::string& url, std::string& postData, std::string& responseData ); | ||
28 | }; | 31 | }; |
29 | } | 32 | } |
30 | 33 |
@@ -13,8 +13,11 @@ | @@ -13,8 +13,11 @@ | ||
13 | #define MAX_SIZE 40 | 13 | #define MAX_SIZE 40 |
14 | namespace mapserver | 14 | namespace mapserver |
15 | { | 15 | { |
16 | - DmpPgsqlPool::DmpPgsqlPool() | 16 | + DmpPgsqlPool::DmpPgsqlPool(const std::string& guid,const std::string& name, const std::string& alias) |
17 | { | 17 | { |
18 | + guid_ = guid; | ||
19 | + name_ = name; | ||
20 | + alias_ = alias; | ||
18 | waitConnectSize_ = MAX_SIZE; | 21 | waitConnectSize_ = MAX_SIZE; |
19 | connectionTimeout_ = 15000; | 22 | connectionTimeout_ = 15000; |
20 | } | 23 | } |
@@ -19,42 +19,42 @@ | @@ -19,42 +19,42 @@ | ||
19 | namespace mapserver | 19 | namespace mapserver |
20 | { | 20 | { |
21 | class DmpPgsqlPool | 21 | class DmpPgsqlPool |
22 | - { | ||
23 | -public: | ||
24 | - DmpPgsqlPool(); | 22 | + { |
23 | + public: | ||
24 | + DmpPgsqlPool(const std::string& guid,const std::string& name, const std::string& alias); | ||
25 | ~DmpPgsqlPool(); | 25 | ~DmpPgsqlPool(); |
26 | - void ScannerConnectionTask(); | 26 | + void ScannerConnectionTask(); |
27 | std::shared_ptr<DmpPgsql> TestDmpPgsql(void); | 27 | std::shared_ptr<DmpPgsql> TestDmpPgsql(void); |
28 | - std::shared_ptr<DmpPgsql> GetPgsqlConn(void); | ||
29 | - void ReleaseHandle(DmpPgsql*); | 28 | + std::shared_ptr<DmpPgsql> GetPgsqlConn(void); |
29 | + void ReleaseHandle(DmpPgsql *); | ||
30 | 30 | ||
31 | void Close(void); | 31 | void Close(void); |
32 | - bool Connect(const char * s); | ||
33 | - DmpPgsql* GetConnect(); | ||
34 | - std::string guid()const { return guid_;} | ||
35 | - std::string name()const { return name_;} | ||
36 | - std::string alias()const{ return alias_;} | ||
37 | - | ||
38 | -private: | ||
39 | - std::string conninfo_; | 32 | + bool Connect(const char *s); |
33 | + DmpPgsql *GetConnect(); | ||
34 | + std::string guid() const { return guid_; } | ||
35 | + std::string name() const { return name_; } | ||
36 | + std::string alias() const { return alias_; } | ||
37 | + | ||
38 | + | ||
39 | + | ||
40 | + private: | ||
41 | + std::string conninfo_; | ||
40 | // 存储连接的队列 | 42 | // 存储连接的队列 |
41 | - queue<DmpPgsql*> connectionQue_; | 43 | + queue<DmpPgsql *> connectionQue_; |
42 | int waitConnectSize_; | 44 | int waitConnectSize_; |
43 | int connectSize_ = 0; | 45 | int connectSize_ = 0; |
44 | mutex mutex_; | 46 | mutex mutex_; |
45 | //连接超时时间 | 47 | //连接超时时间 |
46 | - int connectionTimeout_; | ||
47 | - | ||
48 | - // 设置条件变量,用于连接生产线程和连接消费线程的通信 | ||
49 | - condition_variable cv_; | ||
50 | - bool isClose_ = false; | ||
51 | - std::string guid_; | ||
52 | - std::string name_; | ||
53 | - std::string alias_; | 48 | + int connectionTimeout_; |
49 | + | ||
50 | + // 设置条件变量,用于连接生产线程和连接消费线程的通信 | ||
51 | + condition_variable cv_; | ||
52 | + bool isClose_ = false; | ||
53 | + std::string guid_; | ||
54 | + std::string name_; | ||
55 | + std::string alias_; | ||
54 | }; | 56 | }; |
55 | - | ||
56 | -} | ||
57 | 57 | ||
58 | +} | ||
58 | 59 | ||
59 | #endif //__dmppgsqlpool_h__ | 60 | #endif //__dmppgsqlpool_h__ |
60 | - |
@@ -11,6 +11,13 @@ | @@ -11,6 +11,13 @@ | ||
11 | #include <iostream> | 11 | #include <iostream> |
12 | #include "dmphttpbase.h" | 12 | #include "dmphttpbase.h" |
13 | #include "dmphttputils.h" | 13 | #include "dmphttputils.h" |
14 | +#include "dmpmapserverutil.h" | ||
15 | +#include "dmpserverutils.h" | ||
16 | +#include "dmpserverdes.h" | ||
17 | +#include <boost/property_tree/ptree.hpp> | ||
18 | +#include <boost/property_tree/json_parser.hpp> | ||
19 | +#include <boost/typeof/typeof.hpp> | ||
20 | + | ||
14 | //#include "DES.h" | 21 | //#include "DES.h" |
15 | //#include "StringHelp.h" | 22 | //#include "StringHelp.h" |
16 | 23 | ||
@@ -168,22 +175,7 @@ namespace mapserver | @@ -168,22 +175,7 @@ namespace mapserver | ||
168 | return ""; | 175 | return ""; |
169 | } | 176 | } |
170 | 177 | ||
171 | - string DmpPgsqlSourcePools::GetDbsource(const string& serviceid) | ||
172 | - { | ||
173 | - string requestUrl = DmpServerConfig::Instance()->getMetaUrl(); | ||
174 | - if(requestUrl.size() >0 && requestUrl[requestUrl.size() -1] !='/') | ||
175 | - { | ||
176 | - requestUrl += "/"; | ||
177 | - } | ||
178 | - requestUrl.append("API/Database/Detail"); | ||
179 | - | ||
180 | - std::string strContent= DmpHttp::post(requestUrl); | ||
181 | - if(strContent.length()==0) | ||
182 | - { | ||
183 | - return ""; | ||
184 | - } | ||
185 | - return requestUrl; | ||
186 | - } | 178 | + |
187 | 179 | ||
188 | 180 | ||
189 | bool DmpPgsqlSourcePools::UpdateDatabasePool() | 181 | bool DmpPgsqlSourcePools::UpdateDatabasePool() |
@@ -339,13 +331,6 @@ namespace mapserver | @@ -339,13 +331,6 @@ namespace mapserver | ||
339 | string alias = pPgsqlConn->getString(2); | 331 | string alias = pPgsqlConn->getString(2); |
340 | string uri = pPgsqlConn->getString(3); | 332 | string uri = pPgsqlConn->getString(3); |
341 | string connectstr = pPgsqlConn->getString(4); | 333 | string connectstr = pPgsqlConn->getString(4); |
342 | - /* if(guid == "74c73a18-00c9-11ec-aced-0242ac110002") | ||
343 | - { | ||
344 | - continue; | ||
345 | - }*/ | ||
346 | - | ||
347 | - | ||
348 | - | ||
349 | string pgConnect= ""; | 334 | string pgConnect= ""; |
350 | if(connectstr != "") | 335 | if(connectstr != "") |
351 | { | 336 | { |
@@ -460,25 +445,93 @@ namespace mapserver | @@ -460,25 +445,93 @@ namespace mapserver | ||
460 | 445 | ||
461 | bool DmpPgsqlSourcePools::CreateDefaultDatabasePool(string dataType, string connStr) | 446 | bool DmpPgsqlSourcePools::CreateDefaultDatabasePool(string dataType, string connStr) |
462 | { | 447 | { |
463 | - shared_ptr<DmpPgsqlPool> newPool(new DmpPgsqlPool()); | 448 | + shared_ptr<DmpPgsqlPool> newPool(new DmpPgsqlPool("","","")); |
464 | defaultPool_ = newPool; | 449 | defaultPool_ = newPool; |
465 | bool result = defaultPool_->Connect(connStr.c_str()); | 450 | bool result = defaultPool_->Connect(connStr.c_str()); |
466 | - | 451 | + |
467 | return true; | 452 | return true; |
468 | } | 453 | } |
469 | 454 | ||
470 | - bool DmpPgsqlSourcePools::AddDatabasePool(string guid) | 455 | + bool DmpPgsqlSourcePools::AddDatabasePool(string guid) |
471 | { | 456 | { |
472 | - | ||
473 | - shared_ptr<DmpPgsqlPool> newPool(new DmpPgsqlPool()); | ||
474 | - // newPool->guid() = guid; | ||
475 | - // newPool->m_name = databaseName; | ||
476 | - // newPool->m_alias = alias; | ||
477 | - std::string connStr = this->GetDbsource(guid); | ||
478 | - newPool->Connect(connStr.c_str()); | ||
479 | - //newPool->Connect("PostgreSQLConn=hostaddr=172.26.99.173 port=5433 dbname='postgres' user='postgres' password='chinadci'"); | ||
480 | - pgsqlPool_[guid] = newPool; | ||
481 | - return true; | 457 | + if (guid.find(" ") != string::npos && guid.size() > 50) |
458 | + { | ||
459 | + std::string connStr = guid; | ||
460 | + shared_ptr<DmpPgsqlPool> newPool(new DmpPgsqlPool(guid,guid,guid)); | ||
461 | + newPool->Connect(connStr.c_str()); | ||
462 | + //newPool->Connect("PostgreSQLConn=hostaddr=172.26.99.173 port=5433 dbname='postgres' user='postgres' password='chinadci'"); | ||
463 | + pgsqlPool_[guid] = newPool; | ||
464 | + return true; | ||
465 | + } | ||
466 | + else | ||
467 | + { | ||
468 | + string requestUrl = DmpServerConfig::Instance()->getMetaUrl(); | ||
469 | + if (requestUrl.size() > 0 && requestUrl[requestUrl.size() - 1] != '/') | ||
470 | + { | ||
471 | + requestUrl += "/"; | ||
472 | + } | ||
473 | + requestUrl.append("API/Database/Detail?guid="); | ||
474 | + requestUrl.append(guid); | ||
475 | + std::string reponse_data = DmpServerConfig::Instance()->HttpGet(requestUrl); | ||
476 | + if (!reponse_data.empty()) | ||
477 | + { | ||
478 | + try | ||
479 | + { | ||
480 | + std::stringstream stream(reponse_data); | ||
481 | + boost::property_tree::ptree pt; | ||
482 | + boost::property_tree::read_json(stream, pt); | ||
483 | + std::string name = pt.get<std::string>("data.name"); | ||
484 | + std::string alias = pt.get<std::string>("data.alias"); | ||
485 | + std::string sqlalchemy_uri_base64 = pt.get<std::string>("data.connectstr"); | ||
486 | + std::string sqlalchemy_uri = DmpServerDes::DesBase64Decrypt(sqlalchemy_uri_base64, "Chinadci"); | ||
487 | + | ||
488 | + shared_ptr<DmpPgsqlPool> newPool(new DmpPgsqlPool(guid,name,alias)); | ||
489 | + if (newPool->Connect(sqlalchemy_uri.c_str())) | ||
490 | + { | ||
491 | + pgsqlPool_[guid] = newPool; | ||
492 | + return true; | ||
493 | + } | ||
494 | + | ||
495 | + } | ||
496 | + catch (...) | ||
497 | + { | ||
498 | + return false; | ||
499 | + } | ||
500 | + } | ||
501 | + } | ||
502 | + return false; | ||
503 | + } | ||
504 | + | ||
505 | + string DmpPgsqlSourcePools::GetDbsource(const string& serviceid) | ||
506 | + { | ||
507 | + string requestUrl = DmpServerConfig::Instance()->getMetaUrl(); | ||
508 | + if (requestUrl.size() > 0 && requestUrl[requestUrl.size() - 1] != '/') | ||
509 | + { | ||
510 | + requestUrl += "/"; | ||
511 | + } | ||
512 | + requestUrl.append("API/Database/Detail?guid="); | ||
513 | + requestUrl.append(serviceid); | ||
514 | + std::string reponse_data = DmpServerConfig::Instance()->HttpGet(requestUrl); | ||
515 | + if (!reponse_data.empty()) | ||
516 | + { | ||
517 | + try | ||
518 | + { | ||
519 | + std::stringstream stream(reponse_data); | ||
520 | + boost::property_tree::ptree pt; | ||
521 | + boost::property_tree::read_json(stream, pt); | ||
522 | + std::string name = pt.get<std::string>("data.name"); | ||
523 | + std::string alias = pt.get<std::string>("data.alias"); | ||
524 | + std::string sqlalchemy_uri_base64 = pt.get<std::string>("data.connectstr"); | ||
525 | + std::string sqlalchemy_uri = DmpServerDes::DesBase64Decrypt(sqlalchemy_uri_base64, "Chinadci"); | ||
526 | + | ||
527 | + return sqlalchemy_uri; | ||
528 | + } | ||
529 | + catch (...) | ||
530 | + { | ||
531 | + return ""; | ||
532 | + } | ||
533 | + } | ||
534 | + return ""; | ||
482 | } | 535 | } |
483 | 536 | ||
484 | bool DmpPgsqlSourcePools::AddDatabasePool(string dataType, | 537 | bool DmpPgsqlSourcePools::AddDatabasePool(string dataType, |
@@ -488,7 +541,7 @@ namespace mapserver | @@ -488,7 +541,7 @@ namespace mapserver | ||
488 | string connStr) | 541 | string connStr) |
489 | { | 542 | { |
490 | 543 | ||
491 | - shared_ptr<DmpPgsqlPool> newPool(new DmpPgsqlPool()); | 544 | + shared_ptr<DmpPgsqlPool> newPool(new DmpPgsqlPool(guid,databaseName,alias)); |
492 | // newPool->guid() = guid; | 545 | // newPool->guid() = guid; |
493 | // newPool->m_name = databaseName; | 546 | // newPool->m_name = databaseName; |
494 | // newPool->m_alias = alias; | 547 | // newPool->m_alias = alias; |
@@ -502,7 +555,7 @@ namespace mapserver | @@ -502,7 +555,7 @@ namespace mapserver | ||
502 | { | 555 | { |
503 | if(pgsqlPool_.find(guid) == pgsqlPool_.end()) | 556 | if(pgsqlPool_.find(guid) == pgsqlPool_.end()) |
504 | { | 557 | { |
505 | - shared_ptr<DmpPgsqlPool> newPool(new DmpPgsqlPool()); | 558 | + shared_ptr<DmpPgsqlPool> newPool(new DmpPgsqlPool(guid,databaseName,alias)); |
506 | // newPool->guid() = guid; | 559 | // newPool->guid() = guid; |
507 | // newPool->m_name = databaseName; | 560 | // newPool->m_name = databaseName; |
508 | // newPool->m_alias = alias; | 561 | // newPool->m_alias = alias; |
@@ -7,7 +7,6 @@ | @@ -7,7 +7,6 @@ | ||
7 | * copyright: 广州城市信息研究所有限公司 | 7 | * copyright: 广州城市信息研究所有限公司 |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | - | ||
11 | #ifndef __dmppgsqlsourcepools_h__ | 10 | #ifndef __dmppgsqlsourcepools_h__ |
12 | #define __dmppgsqlsourcepools_h__ | 11 | #define __dmppgsqlsourcepools_h__ |
13 | 12 | ||
@@ -22,50 +21,47 @@ | @@ -22,50 +21,47 @@ | ||
22 | 21 | ||
23 | namespace mapserver | 22 | namespace mapserver |
24 | { | 23 | { |
25 | - class DmpPgsqlPool; | ||
26 | - class DmpPgsqlSourcePools | ||
27 | - { | ||
28 | - public: | ||
29 | - | ||
30 | - DmpPgsqlSourcePools(); | ||
31 | - ~DmpPgsqlSourcePools(); | ||
32 | - static DmpPgsqlSourcePools* get_instance(); | 24 | + class DmpPgsqlPool; |
25 | + class DmpPgsqlSourcePools | ||
26 | + { | ||
27 | + public: | ||
28 | + DmpPgsqlSourcePools(); | ||
29 | + ~DmpPgsqlSourcePools(); | ||
30 | + static DmpPgsqlSourcePools *get_instance(); | ||
33 | 31 | ||
34 | - //获取默认数据库连接 | ||
35 | - shared_ptr<DmpPgsql> GetDefaultPgsqlConn(); | 32 | + //获取默认数据库连接 |
33 | + shared_ptr<DmpPgsql> GetDefaultPgsqlConn(); | ||
36 | 34 | ||
37 | - //获取数据库连接 | ||
38 | - shared_ptr<DmpPgsql> GetPgsqlConn(const string& name); | 35 | + //获取数据库连接 |
36 | + shared_ptr<DmpPgsql> GetPgsqlConn(const string &name); | ||
39 | 37 | ||
40 | - // shared_ptr<DmpPgsql> GetPgsqlConn(char* name); | 38 | + // shared_ptr<DmpPgsql> GetPgsqlConn(char* name); |
41 | 39 | ||
42 | - string GetDbSourceID(string name); | 40 | + string GetDbSourceID(string name); |
43 | 41 | ||
44 | - string GetDbsource(const string& serviceid); | 42 | + string GetDbsource(const string& serviceid); |
45 | 43 | ||
44 | + bool InitDatabasePool(); | ||
46 | 45 | ||
47 | - bool InitDatabasePool(); | 46 | + bool UpdateDatabasePool(); |
47 | + //创建默认数据库连接池 | ||
48 | + bool CreateDefaultDatabasePool(string dataType, string connStr); | ||
49 | + // 添加数据库连接池 | ||
50 | + bool AddDatabasePool(string dataType, string guid, string databaseName, string alias, string connStr); | ||
51 | + // Update 数据库连接池 | ||
52 | + bool UpdDatabasePool(string dataType, string guid, string databaseName, string alias, string connStr); | ||
48 | 53 | ||
49 | - bool UpdateDatabasePool(); | ||
50 | - //创建默认数据库连接池 | ||
51 | - bool CreateDefaultDatabasePool(string dataType, string connStr); | ||
52 | - // 添加数据库连接池 | ||
53 | - bool AddDatabasePool(string dataType, string guid, string databaseName, string alias, string connStr); | ||
54 | - // Update 数据库连接池 | ||
55 | - bool UpdDatabasePool(string dataType, string guid, string databaseName, string alias, string connStr); | 54 | + bool AddDatabasePool(string guid); |
56 | 55 | ||
57 | - bool AddDatabasePool(string guid); | ||
58 | - private: | ||
59 | - shared_ptr<DmpPgsqlPool> defaultPool_; | ||
60 | - map<string, shared_ptr<DmpPgsqlPool>> pgsqlPool_; | ||
61 | - bool updateLock_ = false; | 56 | + private: |
57 | + shared_ptr<DmpPgsqlPool> defaultPool_; | ||
58 | + map<string, shared_ptr<DmpPgsqlPool>> pgsqlPool_; | ||
59 | + bool updateLock_ = false; | ||
62 | 60 | ||
63 | - private: | ||
64 | - mutex mutex_; | ||
65 | - static DmpPgsqlSourcePools* instance_ptr; | ||
66 | - }; | 61 | + private: |
62 | + mutex mutex_; | ||
63 | + static DmpPgsqlSourcePools *instance_ptr; | ||
64 | + }; | ||
67 | } | 65 | } |
68 | 66 | ||
69 | - | ||
70 | #endif //__dmppgsqlsourcepools_h__ | 67 | #endif //__dmppgsqlsourcepools_h__ |
71 | - |
@@ -58,16 +58,6 @@ namespace DmpMapping | @@ -58,16 +58,6 @@ namespace DmpMapping | ||
58 | { | 58 | { |
59 | editService(context, vectorMappingProjects_); | 59 | editService(context, vectorMappingProjects_); |
60 | } | 60 | } |
61 | - else if (boost::iequals(request, "getmap")) | ||
62 | - { | ||
63 | - const std::string mapGuid = params.MapGuid(); | ||
64 | - if(vectorMappingProjects_.find(mapGuid) != vectorMappingProjects_.end()) | ||
65 | - { | ||
66 | - shared_ptr<DmpProject> project = vectorMappingProjects_.find(mapGuid)->second; | ||
67 | - const DmpWms::DmpWmsParameters wmsParams(context.request()->serverParameters()); | ||
68 | - DmpWms::writeGetMap(context, wmsParams, project.get()); | ||
69 | - } | ||
70 | - } | ||
71 | else if (boost::iequals(request,"gettypefacelist")) { | 61 | else if (boost::iequals(request,"gettypefacelist")) { |
72 | getTypefaceList(context); | 62 | getTypefaceList(context); |
73 | } | 63 | } |
@@ -80,6 +70,57 @@ namespace DmpMapping | @@ -80,6 +70,57 @@ namespace DmpMapping | ||
80 | else if (boost::iequals(request,"getimage")) { | 70 | else if (boost::iequals(request,"getimage")) { |
81 | getImage(context); | 71 | getImage(context); |
82 | } | 72 | } |
73 | + else if (boost::iequals(request, "getmap")) | ||
74 | + { | ||
75 | + const std::string mapGuid = params.MapGuid(); | ||
76 | + if (vectorMappingProjects_.find(mapGuid) != vectorMappingProjects_.end()) | ||
77 | + { | ||
78 | + shared_ptr<DmpProject> project = vectorMappingProjects_.find(mapGuid)->second; | ||
79 | + const DmpWms::DmpWmsParameters wmsParams(context.request()->serverParameters()); | ||
80 | + DmpWms::writeGetMap(context, wmsParams, project.get()); | ||
81 | + } | ||
82 | + else | ||
83 | + { | ||
84 | + writeLock(rwmutex_); | ||
85 | + if (vectorMappingProjects_.find(mapGuid) != vectorMappingProjects_.end()) | ||
86 | + { | ||
87 | + shared_ptr<DmpProject> project = vectorMappingProjects_.find(mapGuid)->second; | ||
88 | + const DmpWms::DmpWmsParameters wmsParams(context.request()->serverParameters()); | ||
89 | + DmpWms::writeGetMap(context, wmsParams, project.get()); | ||
90 | + } | ||
91 | + else | ||
92 | + { | ||
93 | + std::string mapRenderer = params.MapRenderer(); | ||
94 | + if (!mapRenderer.empty()) | ||
95 | + { | ||
96 | + std::string projData; | ||
97 | + for(int i = 0; i< mapRenderer.size(); i++) | ||
98 | + { | ||
99 | + if(mapRenderer[i] == ' ')mapRenderer[i]= '+'; | ||
100 | + } | ||
101 | + if (!DmpServerUtils::Base64Decode(mapRenderer, &projData)) | ||
102 | + { | ||
103 | + context.response()->writeJson("{\"status\":\"false\",\"message\":\""+ mapRenderer +" base64转码错误\"}"); | ||
104 | + return; | ||
105 | + } | ||
106 | + shared_ptr<DmpProject> project(new DmpProject()); | ||
107 | + if (!project->Read(projData)) | ||
108 | + { | ||
109 | + context.response()->writeJson("{\"status\":\"false\",\"message\":\"DMD文档错误\"}"); | ||
110 | + return; | ||
111 | + } | ||
112 | + const DmpWms::DmpWmsParameters wmsParams(context.request()->serverParameters()); | ||
113 | + DmpWms::writeGetMap(context, wmsParams, project.get()); | ||
114 | + if(!mapGuid.empty()) | ||
115 | + { | ||
116 | + vectorMappingProjects_[mapGuid] = project; | ||
117 | + } | ||
118 | + return; | ||
119 | + } | ||
120 | + } | ||
121 | + } | ||
122 | + } | ||
123 | + | ||
83 | } | 124 | } |
84 | 125 | ||
85 | 126 |
@@ -12,6 +12,12 @@ | @@ -12,6 +12,12 @@ | ||
12 | #include <string> | 12 | #include <string> |
13 | #include "dmpeditservice.h" | 13 | #include "dmpeditservice.h" |
14 | #include "dmpservice.h" | 14 | #include "dmpservice.h" |
15 | +#include <boost/thread/shared_mutex.hpp> | ||
16 | +#include <boost/thread.hpp> | ||
17 | + | ||
18 | +typedef boost::shared_mutex rwmutex; | ||
19 | +typedef boost::shared_lock<rwmutex> readLock; | ||
20 | +typedef boost::unique_lock<rwmutex> writeLock; | ||
15 | namespace DmpMapping | 21 | namespace DmpMapping |
16 | { | 22 | { |
17 | class DmpMappingService : public DmpService | 23 | class DmpMappingService : public DmpService |
@@ -28,6 +34,7 @@ namespace DmpMapping | @@ -28,6 +34,7 @@ namespace DmpMapping | ||
28 | 34 | ||
29 | //存储工程文档实例 | 35 | //存储工程文档实例 |
30 | ProjectMap vectorMappingProjects_; | 36 | ProjectMap vectorMappingProjects_; |
37 | + rwmutex rwmutex_; | ||
31 | }; | 38 | }; |
32 | } | 39 | } |
33 | 40 |
@@ -104,4 +104,11 @@ namespace DmpMapping | @@ -104,4 +104,11 @@ namespace DmpMapping | ||
104 | return value; | 104 | return value; |
105 | } | 105 | } |
106 | 106 | ||
107 | + std::string DmpMappingParameters::MapRenderer() const | ||
108 | + { | ||
109 | + std::string value = ""; | ||
110 | + GetStringParameter("MapRenderer", value); | ||
111 | + return value; | ||
112 | + } | ||
113 | + | ||
107 | } // namespace DmpWms | 114 | } // namespace DmpWms |
@@ -25,6 +25,7 @@ namespace DmpMapping | @@ -25,6 +25,7 @@ namespace DmpMapping | ||
25 | 25 | ||
26 | std::string Map() const; | 26 | std::string Map() const; |
27 | std::string MapGuid() const; | 27 | std::string MapGuid() const; |
28 | + std::string MapRenderer() const; | ||
28 | 29 | ||
29 | private: | 30 | private: |
30 | bool GetStringParameter(const char* key, std::string &value) const; | 31 | bool GetStringParameter(const char* key, std::string &value) const; |
@@ -72,9 +72,14 @@ namespace DmpWms | @@ -72,9 +72,14 @@ namespace DmpWms | ||
72 | mapRenderer.SetExtent(rect); | 72 | mapRenderer.SetExtent(rect); |
73 | string responseData; | 73 | string responseData; |
74 | mapRenderer.GetFeatureInfo(responseData, x, y, featureCount); | 74 | mapRenderer.GetFeatureInfo(responseData, x, y, featureCount); |
75 | - context.response()->removeHeader("Content-Type"); | ||
76 | - context.response()->setHeader("Content-Type", "image/png"); | ||
77 | - context.response()->write(responseData); | 75 | + if(responseData.empty()) |
76 | + { | ||
77 | + context.response()->writeJson("null"); | ||
78 | + } | ||
79 | + else | ||
80 | + { | ||
81 | + context.response()->writeJson(responseData); | ||
82 | + } | ||
78 | return ""; | 83 | return ""; |
79 | } | 84 | } |
80 | catch (const std::exception &e) | 85 | catch (const std::exception &e) |
@@ -522,7 +522,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -522,7 +522,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
522 | else if (typeString == "integer") | 522 | else if (typeString == "integer") |
523 | { | 523 | { |
524 | typeInt = PGFieldType::BigIntFieldType; | 524 | typeInt = PGFieldType::BigIntFieldType; |
525 | - fields_str += " \"" + (fieldname) + "\" "; | 525 | + fields_str += " \"" + (fieldname) + "\"::varchar "; |
526 | } | 526 | } |
527 | else if (typeString == "bigint") | 527 | else if (typeString == "bigint") |
528 | { | 528 | { |
@@ -532,7 +532,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -532,7 +532,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
532 | else if (typeString == "double precision" || typeString == "real" || typeString == "numeric") | 532 | else if (typeString == "double precision" || typeString == "real" || typeString == "numeric") |
533 | { | 533 | { |
534 | typeInt = PGFieldType::DoubleFieldType; | 534 | typeInt = PGFieldType::DoubleFieldType; |
535 | - fields_str += " \"" + (fieldname) + "\" "; | 535 | + fields_str += " \"" + (fieldname) + "\"::varchar "; |
536 | } | 536 | } |
537 | else if (typeString == "character varying" || typeString == "text") | 537 | else if (typeString == "character varying" || typeString == "text") |
538 | { | 538 | { |
@@ -572,7 +572,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -572,7 +572,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
572 | 572 | ||
573 | string shapeName = layer->geom(); | 573 | string shapeName = layer->geom(); |
574 | sql += format(" ST_DWithin(\"%s\", ST_GeometryFromText('POINT(%f %f)',%s), %f) limit %d ", | 574 | sql += format(" ST_DWithin(\"%s\", ST_GeometryFromText('POINT(%f %f)',%s), %f) limit %d ", |
575 | - shapeName.c_str(), x, y, layer->crs().srid(), dis, feature_count); | 575 | + shapeName.c_str(), x, y, layer->srid().c_str(), dis, feature_count); |
576 | //cout<<sql.c_str() <<endl; | 576 | //cout<<sql.c_str() <<endl; |
577 | return sql; | 577 | return sql; |
578 | } | 578 | } |
@@ -604,7 +604,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -604,7 +604,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
604 | string sql = this->GetFeatureInfoSQL(layer, x0, y0, dis, feature_count); //sql语句中使用 ::box | 604 | string sql = this->GetFeatureInfoSQL(layer, x0, y0, dis, feature_count); //sql语句中使用 ::box |
605 | if (sql == "") | 605 | if (sql == "") |
606 | continue; | 606 | continue; |
607 | - | 607 | + printf("%s\r\n",sql.c_str()); |
608 | string layerName = layer->name(); | 608 | string layerName = layer->name(); |
609 | try | 609 | try |
610 | { | 610 | { |
请
注册
或
登录
后发表评论