metaproxy 1.22.4
metaproxy_1::RouterFleXML::Rep Class Reference
Collaboration diagram for metaproxy_1::RouterFleXML::Rep:
Collaboration graph

Private Types

typedef std::map< std::string, boost::shared_ptr< const mp::filter::Base > > IdFilterMap

Private Member Functions

 Rep ()
void base (xmlDocPtr doc, mp::FactoryFilter &factory, bool test_only, const char *file_include_path)
void parse_xml_config_dom (xmlDocPtr doc, bool test_only, const char *file_include_path)
void parse_xml_filters (xmlDocPtr doc, const xmlNode *node, bool test_only, const char *file_include_path)
void parse_xml_filters1 (xmlDocPtr doc, const xmlNode *node, bool test_only, const char *file_include_path, Route &route)
void parse_xml_routes (xmlDocPtr doc, const xmlNode *node, bool test_only, const char *file_include_path)
void check_routes_in_filters (const xmlNode *n)

Private Attributes

IdFilterMap m_id_filter_map
std::map< std::string, RouterFleXML::Route > m_routes
std::string m_start_route
std::string m_dl_path
bool m_xinclude
FactoryFilter * m_factory

Friends

class RouterFleXML
class RouterFleXML::Pos

Detailed Description

Definition at line 47 of file router_flexml.cpp.

Member Typedef Documentation

◆ IdFilterMap

typedef std::map<std::string, boost::shared_ptr<const mp::filter::Base > > metaproxy_1::RouterFleXML::Rep::IdFilterMap
private

Definition at line 57 of file router_flexml.cpp.

Constructor & Destructor Documentation

◆ Rep()

metaproxy_1::RouterFleXML::Rep::Rep ( )
private

Definition at line 409 of file router_flexml.cpp.

409 : m_xinclude(false)
410{
411}

References m_xinclude.

Member Function Documentation

◆ base()

void metaproxy_1::RouterFleXML::Rep::base ( xmlDocPtr doc,
mp::FactoryFilter & factory,
bool test_only,
const char * file_include_path )
private

Definition at line 413 of file router_flexml.cpp.

415{
416 m_factory = &factory;
417 m_start_route = "start";
418 parse_xml_config_dom(doc, test_only, file_include_path);
419}
void parse_xml_config_dom(xmlDocPtr doc, bool test_only, const char *file_include_path)

References m_factory, m_start_route, and parse_xml_config_dom().

Here is the call graph for this function:

◆ check_routes_in_filters()

void metaproxy_1::RouterFleXML::Rep::check_routes_in_filters ( const xmlNode * n)
private

Definition at line 266 of file router_flexml.cpp.

267{
268 while (node)
269 {
270 if (mp::xml::is_element_mp(node, "filters"))
271 {
272 const xmlNode *n =
273 mp::xml::jump_to_children(node, XML_ELEMENT_NODE);
275 }
276 else if (mp::xml::is_element_mp(node, "filter"))
277 {
278 const xmlNode *n =
279 mp::xml::jump_to_children(node, XML_ELEMENT_NODE);
280 while (n)
281 {
282 const struct _xmlAttr *attr;
283 // we assume thar that route attribute is only at one level
284 // below filter.. At least that works for multi and virt_db.
285 for (attr = n->properties; attr; attr = attr->next)
286 {
287 if (!strcmp((const char *) attr->name, "route"))
288 {
289 std::string value;
290
291 if (attr->children && attr->children->type == XML_TEXT_NODE)
292 value = std::string((const char *)attr->children->content);
293
294 std::map<std::string,RouterFleXML::Route>::iterator it;
295 it = m_routes.find(value);
296 if (it == m_routes.end())
297 {
298 throw mp::XMLError("Route '" + value + "' does not exist");
299 }
300 }
301 }
302 n = mp::xml::jump_to_next(n, XML_ELEMENT_NODE);
303 }
304 }
305 node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE);
306 }
307}
void check_routes_in_filters(const xmlNode *n)
std::map< std::string, RouterFleXML::Route > m_routes

References check_routes_in_filters(), and m_routes.

Referenced by check_routes_in_filters(), and parse_xml_config_dom().

Here is the call graph for this function:

◆ parse_xml_config_dom()

void metaproxy_1::RouterFleXML::Rep::parse_xml_config_dom ( xmlDocPtr doc,
bool test_only,
const char * file_include_path )
private

Definition at line 309 of file router_flexml.cpp.

312{
313 if (!doc)
314 throw mp::XMLError("Empty XML Document");
315
316 const xmlNode* root = xmlDocGetRootElement(doc);
317
318 if (file_include_path)
319 {
320 int r = yaz_xml_include_glob((xmlNode *) root, file_include_path,
321 YAZ_FILE_GLOB_FAIL_NOTEXIST);
322 if (r)
323 throw mp::XMLError("YAZ XML Include failed");
324 }
325
326 mp::xml::check_element_mp(root, "metaproxy");
327
328 const xmlNode* node = mp::xml::jump_to_children(root, XML_ELEMENT_NODE);
329
330 if (mp::xml::is_element_mp(node, "dlpath"))
331 {
332 m_dl_path = mp::xml::get_text(node);
333 node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE);
334 }
335 // process <start> node which is expected first element node
336 if (mp::xml::check_element_mp(node, "start"))
337 {
338 const struct _xmlAttr *attr;
339 for (attr = node->properties; attr; attr = attr->next)
340 {
341 std::string name = std::string((const char *) attr->name);
342 std::string value;
343
344 if (attr->children && attr->children->type == XML_TEXT_NODE)
345 value = std::string((const char *)attr->children->content);
346
347 if (name == "route")
348 m_start_route = value;
349 else if (name == "base")
350 ;// Ignore XInclude base attribute.
351 else
352 throw mp::XMLError("Only attribute route allowed"
353 " in element 'start'. Got " + name);
354 }
355 node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE);
356 }
357 // process <filters> node if given
358 if (mp::xml::is_element_mp(node, "filters"))
359 {
360 parse_xml_filters(doc, mp::xml::jump_to_children(node,
361 XML_ELEMENT_NODE),
362 test_only, file_include_path);
363
364 node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE);
365 }
366 // process <routes> node which is expected third element node
367 mp::xml::check_element_mp(node, "routes");
368
369 parse_xml_routes(doc, mp::xml::jump_to_children(node, XML_ELEMENT_NODE),
370 test_only, file_include_path);
371
372 node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE);
373 if (node)
374 {
375 throw mp::XMLError("Unexpected element "
376 + std::string((const char *)node->name));
377 }
378
379 node = mp::xml::jump_to_children(root, XML_ELEMENT_NODE);
380 while (node)
381 {
382 if (mp::xml::is_element_mp(node, "filters"))
384 mp::xml::jump_to_children(node,
385 XML_ELEMENT_NODE));
386 else if (mp::xml::is_element_mp(node, "routes"))
387 {
388 const xmlNode* n = mp::xml::jump_to_children(node,
389 XML_ELEMENT_NODE);
390 while (n)
391 {
392 if (mp::xml::is_element_mp(n, "route"))
393 {
395 mp::xml::jump_to_children(n, XML_ELEMENT_NODE));
396
397 }
398 n = mp::xml::jump_to_next(n, XML_ELEMENT_NODE);
399 }
400 }
401 node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE);
402 }
403 std::map<std::string,RouterFleXML::Route>::iterator it;
404 it = m_routes.find(m_start_route);
405 if (it == m_routes.end())
406 throw mp::XMLError("Start route '" + m_start_route + "' not found");
407}
void parse_xml_filters(xmlDocPtr doc, const xmlNode *node, bool test_only, const char *file_include_path)
void parse_xml_routes(xmlDocPtr doc, const xmlNode *node, bool test_only, const char *file_include_path)

References check_routes_in_filters(), m_dl_path, m_routes, m_start_route, parse_xml_filters(), and parse_xml_routes().

Referenced by base().

Here is the call graph for this function:

◆ parse_xml_filters()

void metaproxy_1::RouterFleXML::Rep::parse_xml_filters ( xmlDocPtr doc,
const xmlNode * node,
bool test_only,
const char * file_include_path )
private

Definition at line 97 of file router_flexml.cpp.

101{
102 while (node && mp::xml::check_element_mp(node, "filter"))
103 {
104 const struct _xmlAttr *attr;
105 std::string id_value;
106 std::string type_value;
107 for (attr = node->properties; attr; attr = attr->next)
108 {
109 std::string name = std::string((const char *) attr->name);
110 std::string value;
111
112 if (attr->children && attr->children->type == XML_TEXT_NODE)
113 value = std::string((const char *)attr->children->content);
114
115 if (name == "id")
116 id_value = value;
117 else if (name == "type")
118 type_value = value;
119 else if (name == "base")
120 ;// Ignore XInclude base attribute.
121 else
122 throw mp::XMLError("Only attribute id or type allowed"
123 " in filter element. Got " + name);
124 }
125
126 if (!m_factory->exist(type_value))
127 {
128 yaz_log(YLOG_LOG, "Loading %s (dlpath %s)",
129 type_value.c_str(), m_dl_path.c_str());
130 m_factory->add_creator_dl(type_value, m_dl_path);
131 }
132 boost::shared_ptr<mp::filter::Base> fb(m_factory->create(type_value));
133
134 fb->configure(node, test_only, file_include_path);
135
136 if (m_id_filter_map.find(id_value) != m_id_filter_map.end())
137 throw mp::XMLError("Filter " + id_value + " already defined");
138
139 m_id_filter_map[id_value] = fb;
140
141 node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE);
142 }
143}

References m_dl_path, m_factory, and m_id_filter_map.

Referenced by parse_xml_config_dom().

◆ parse_xml_filters1()

void metaproxy_1::RouterFleXML::Rep::parse_xml_filters1 ( xmlDocPtr doc,
const xmlNode * node,
bool test_only,
const char * file_include_path,
Route & route )
private

Definition at line 145 of file router_flexml.cpp.

150{
151 while (node)
152 {
153 if (mp::xml::is_element_mp(node, "filters"))
154 {
155 const xmlNode* node1 =
156 mp::xml::jump_to_children(node, XML_ELEMENT_NODE);
157
158 parse_xml_filters1(doc, node1, test_only, file_include_path, route);
159 }
160 else if (mp::xml::check_element_mp(node, "filter"))
161 {
162 const struct _xmlAttr *attr;
163 std::string refid_value;
164 std::string type_value;
165 for (attr = node->properties; attr; attr = attr->next)
166 {
167 std::string name = std::string((const char *) attr->name);
168 std::string value;
169
170 if (attr->children && attr->children->type == XML_TEXT_NODE)
171 value = std::string((const char *)attr->children->content);
172
173 if (name == "refid")
174 refid_value = value;
175 else if (name == "type")
176 type_value = value;
177 else if (name == "base")
178 ;// Ignore XInclude base attribute.
179 else
180 throw mp::XMLError("Only attribute 'refid' or 'type'"
181 " allowed for element 'filter'."
182 " Got " + name);
183 }
184 if (refid_value.length())
185 {
186 std::map<std::string,
187 boost::shared_ptr<const mp::filter::Base > >::iterator it;
188 it = m_id_filter_map.find(refid_value);
189 if (it == m_id_filter_map.end())
190 throw mp::XMLError("Unknown filter refid "
191 + refid_value);
192 else
193 route.m_list.push_back(it->second);
194 }
195 else if (type_value.length())
196 {
197 if (!m_factory->exist(type_value))
198 {
199 yaz_log(YLOG_LOG, "Loading %s (dlpath %s)",
200 type_value.c_str(), m_dl_path.c_str());
201 m_factory->add_creator_dl(type_value, m_dl_path);
202 }
203 boost::shared_ptr<mp::filter::Base>
204 filter_base(m_factory->create(type_value));
205
206 filter_base->configure(node, test_only, file_include_path);
207
208 route.m_list.push_back(filter_base);
209 }
210
211 }
212 node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE);
213 }
214}
void parse_xml_filters1(xmlDocPtr doc, const xmlNode *node, bool test_only, const char *file_include_path, Route &route)

References m_dl_path, m_factory, m_id_filter_map, metaproxy_1::RouterFleXML::Route::m_list, and parse_xml_filters1().

Referenced by parse_xml_filters1(), and parse_xml_routes().

Here is the call graph for this function:

◆ parse_xml_routes()

void metaproxy_1::RouterFleXML::Rep::parse_xml_routes ( xmlDocPtr doc,
const xmlNode * node,
bool test_only,
const char * file_include_path )
private

Definition at line 217 of file router_flexml.cpp.

221{
222 mp::xml::check_element_mp(node, "route");
223
224 while (mp::xml::is_element_mp(node, "route"))
225 {
226 const struct _xmlAttr *attr;
227 std::string id_value;
228 for (attr = node->properties; attr; attr = attr->next)
229 {
230 std::string name = std::string((const char *) attr->name);
231 std::string value;
232
233 if (attr->children && attr->children->type == XML_TEXT_NODE)
234 value = std::string((const char *)attr->children->content);
235
236 if (name == "id")
237 id_value = value;
238 else if (name == "base")
239 ;// Ignore XInclude base attribute.
240 else
241 throw mp::XMLError("Only attribute 'id' allowed for"
242 " element 'route'."
243 " Got " + name);
244 }
245
246 Route route;
247
248 // process <filter> / <filters> nodes in third level
249 const xmlNode* node3 = mp::xml::jump_to_children(node, XML_ELEMENT_NODE);
250
251
252
253 parse_xml_filters1(doc, node3, test_only, file_include_path, route);
254
255 std::map<std::string,RouterFleXML::Route>::iterator it;
256 it = m_routes.find(id_value);
257 if (it != m_routes.end())
258 throw mp::XMLError("Route id='" + id_value
259 + "' already exist");
260 else
261 m_routes[id_value] = route;
262 node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE);
263 }
264}

References m_routes, and parse_xml_filters1().

Referenced by parse_xml_config_dom().

Here is the call graph for this function:

◆ RouterFleXML

friend class RouterFleXML
friend

Definition at line 48 of file router_flexml.cpp.

References RouterFleXML.

Referenced by RouterFleXML.

◆ RouterFleXML::Pos

friend class RouterFleXML::Pos
friend

Definition at line 49 of file router_flexml.cpp.

Member Data Documentation

◆ m_dl_path

std::string metaproxy_1::RouterFleXML::Rep::m_dl_path
private

Definition at line 65 of file router_flexml.cpp.

Referenced by parse_xml_config_dom(), parse_xml_filters(), and parse_xml_filters1().

◆ m_factory

FactoryFilter* metaproxy_1::RouterFleXML::Rep::m_factory
private

Definition at line 81 of file router_flexml.cpp.

Referenced by base(), parse_xml_filters(), and parse_xml_filters1().

◆ m_id_filter_map

IdFilterMap metaproxy_1::RouterFleXML::Rep::m_id_filter_map
private

Definition at line 59 of file router_flexml.cpp.

Referenced by parse_xml_filters(), and parse_xml_filters1().

◆ m_routes

std::map<std::string,RouterFleXML::Route> metaproxy_1::RouterFleXML::Rep::m_routes
private

◆ m_start_route

std::string metaproxy_1::RouterFleXML::Rep::m_start_route
private

Definition at line 63 of file router_flexml.cpp.

Referenced by base(), and parse_xml_config_dom().

◆ m_xinclude

bool metaproxy_1::RouterFleXML::Rep::m_xinclude
private

Definition at line 79 of file router_flexml.cpp.

Referenced by Rep().


The documentation for this class was generated from the following file: