2 * Copyright (c) 1998-2003, Index Data.
3 * See the file LICENSE for details.
5 * $Id: yaz-proxy-config.cpp,v 1.1 2003-10-01 13:13:51 adam Exp $
9 #include <yaz++/proxy.h>
11 Yaz_ProxyConfig::Yaz_ProxyConfig()
20 Yaz_ProxyConfig::~Yaz_ProxyConfig()
23 if (!m_copy && m_docPtr)
28 void Yaz_ProxyConfig::operator=(const Yaz_ProxyConfig &conf)
31 m_docPtr = conf.m_docPtr;
32 m_proxyPtr = conf.m_proxyPtr;
37 int Yaz_ProxyConfig::read_xml(const char *fname)
40 xmlDocPtr ndoc = xmlParseFile(fname);
44 yaz_log(LOG_WARN, "Config file %s not found or parse error", fname);
47 xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
48 if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
49 strcmp((const char *) proxyPtr->name, "proxy"))
51 yaz_log(LOG_WARN, "No proxy element in %s", fname);
55 m_proxyPtr = proxyPtr;
57 // OK: release previous and make it the current one.
68 const char *Yaz_ProxyConfig::get_text(xmlNodePtr ptr)
70 for(ptr = ptr->children; ptr; ptr = ptr->next)
71 if (ptr->type == XML_TEXT_NODE)
73 xmlChar *t = ptr->content;
78 return (const char *) t;
86 void Yaz_ProxyConfig::return_limit(xmlNodePtr ptr,
91 for (ptr = ptr->children; ptr; ptr = ptr->next)
93 if (ptr->type == XML_ELEMENT_NODE
94 && !strcmp((const char *) ptr->name, "bandwidth"))
96 const char *t = get_text(ptr);
100 if (ptr->type == XML_ELEMENT_NODE
101 && !strcmp((const char *) ptr->name, "retrieve"))
103 const char *t = get_text(ptr);
105 *limit_req = atoi(t);
107 if (ptr->type == XML_ELEMENT_NODE
108 && !strcmp((const char *) ptr->name, "pdu"))
110 const char *t = get_text(ptr);
112 *limit_pdu = atoi(t);
119 void Yaz_ProxyConfig::return_target_info(xmlNodePtr ptr,
127 for (; ptr; ptr = ptr->next)
129 if (ptr->type == XML_ELEMENT_NODE
130 && !strcmp((const char *) ptr->name, "url"))
132 const char *t = get_text(ptr);
136 if (ptr->type == XML_ELEMENT_NODE
137 && !strcmp((const char *) ptr->name, "keepalive"))
139 const char *t = get_text(ptr);
145 if (ptr->type == XML_ELEMENT_NODE
146 && !strcmp((const char *) ptr->name, "limit"))
147 return_limit(ptr, limit_bw, limit_pdu, limit_req);
152 void Yaz_ProxyConfig::get_target_info(const char *name,
166 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
168 if (ptr->type == XML_ELEMENT_NODE &&
169 !strcmp((const char *) ptr->name, "target"))
174 // <target default="1"> ?
175 struct _xmlAttr *attr;
176 for (attr = ptr->properties; attr; attr = attr->next)
177 if (!strcmp((const char *) attr->name, "default") &&
178 attr->children && attr->children->type == XML_TEXT_NODE)
180 xmlChar *t = attr->children->content;
183 return_target_info(ptr, url, keepalive,
184 limit_bw, limit_pdu, limit_req);
191 // <target name="name"> ?
192 struct _xmlAttr *attr;
193 for (attr = ptr->properties; attr; attr = attr->next)
194 if (!strcmp((const char *) attr->name, "name"))
197 && attr->children->type==XML_TEXT_NODE
198 && attr->children->content
199 && (!strcmp((const char *) attr->children->content,
201 || !strcmp((const char *) attr->children->content,
205 return_target_info(ptr, url, keepalive,
206 limit_bw, limit_pdu, limit_req);